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.

Methods

app   app_name   attributes   basename   captured   extension   log   model   model_name   params   paths   query   query   redirect   render   resource   response   traits  

Public Instance methods

[Source]

    # File lib/runtime/response_mixin.rb, line 40
40:     def app ; eval(  "::#{app_name.to_s.camel_case}" ) ; end

access stuff from an app

[Source]

    # File lib/runtime/response_mixin.rb, line 39
39:     def app_name ; self.class.rootname.snake_case.to_sym ; end

Attributes are just the query elements specific to the model associated with the current resource.

[Source]

    # File lib/layers/mvc/extensions.rb, line 46
46:     def attributes
47:       query[ model_name ]
48:     end

[Source]

    # File lib/runtime/response_mixin.rb, line 45
45:     def basename ; @basename ||= path.sub(/\.([^\.]+)$/,'') ; end

Elements captured the path

[Source]

    # File lib/runtime/response_mixin.rb, line 22
22:     def captured ; @captured ||= traits.waves.captured ; end

[Source]

    # 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.

[Source]

    # 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.

[Source]

    # 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.

[Source]

    # File lib/layers/mvc/extensions.rb, line 26
26:     def model_name; self.class.basename.snake_case; end

Both the query and capture merged together

[Source]

    # File lib/runtime/response_mixin.rb, line 25
25:     def params 
26:       query = captured ? request.query.merge( captured.to_h ) : request.query
27:       @params ||= Waves::Request::Query.new( query ) 
28:     end

[Source]

    # 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

Access to the query string as a object where the keys are accessors You can still access the original query as request.query

[Source]

    # File lib/runtime/response_mixin.rb, line 19
19:     def query ; @query ||= Waves::Request::Query.new( request.query ) ; end

MVC Params get automatically destructured with the keys as accessors methods. You can still access the original query by calling request.query

[Source]

    # 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

Issue a redirect for the given location.

[Source]

    # File lib/runtime/response_mixin.rb, line 35
35:     def redirect(location, status = '302'); request.redirect(location, status); end

[Source]

    # File lib/runtime/response_mixin.rb, line 53
53:     def render( path, assigns = {} )
54:       Waves::Views::Base.new( request ).render( path, assigns )
55:     end

[Source]

    # File lib/runtime/response_mixin.rb, line 13
13:     def resource ; traits.waves.resource ; end

Access the response.

[Source]

    # File lib/runtime/response_mixin.rb, line 11
11:     def response; request.response; end

[Source]

    # File lib/runtime/response_mixin.rb, line 15
15:     def traits ; request.traits ; end

[Validate]