| Module | Waves::ResponseMixin |
| In: |
lib/layers/mvc/extensions.rb
lib/runtime/response_mixin.rb |
Defines a set of methods that simplify accessing common request and response methods. These include methods not necessarily associated with the Waves::Request and Waves::Response objects, but which may still be useful for constructing a response. This mixin assumes that a @request@ accessor already exists.
# File lib/runtime/response_mixin.rb, line 40
40: def app ; eval( "::#{app_name.to_s.camel_case}" ) ; end
# File lib/runtime/response_mixin.rb, line 45
45: def basename ; @basename ||= path.sub(/\.([^\.]+)$/,'') ; end
# File lib/runtime/response_mixin.rb, line 47
47: def extension
48: @extension ||= if ( m = path.match(/\.([^\.]+)$/) )
49: m[1]
50: end
51: end
Access the Waves::Logger.
# File lib/runtime/response_mixin.rb, line 37
37: def log; Waves::Logger; end
Returns the model corresponding to this controller by naively assuming that model_name must be correct. This allows you to write generic controller methods such as:
model.find( name )
to find an instance of a given model. Again, the plurality of the controller and model must be the same for this to work.
# File lib/layers/mvc/extensions.rb, line 35
35: def model; app::Models[ model_name.intern ]; end
Returns the name of the model corresponding to this controller by taking the basename of the module and converting it to snake case. If the model plurality is different than the controller, this will not, in fact, be the model name.
# File lib/layers/mvc/extensions.rb, line 26
26: def model_name; self.class.basename.snake_case; end
# File lib/runtime/response_mixin.rb, line 41
41: def paths( rname = nil )
42: ( rname.nil? ? resource.class.paths : app::Resources[ rname ].paths ).new( request )
43: end
MVC Params get automatically destructured with the keys as accessors methods. You can still access the original query by calling request.query
# File lib/layers/mvc/extensions.rb, line 39
39: def query
40: @query ||= Waves::Request::Query.new(
41: Waves::Request::Utilities.destructure( request.query ) )
42: end
# File lib/runtime/response_mixin.rb, line 53
53: def render( path, assigns = {} )
54: Waves::Views::Base.new( request ).render( path, assigns )
55: end