Class: Wings::Controller
- Includes:
- Model
- Defined in:
- lib/wings/controller.rb
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Class Method Summary collapse
-
.action(act, rp = {}) ⇒ Object
Respond to Rack The action will be used like a Rack app.
Instance Method Summary collapse
- #dispatch(action, routing_params = {}) ⇒ Object
-
#initialize(env) ⇒ Controller
constructor
A new instance of Controller.
-
#render(template, **opts) ⇒ Object
- options for render
-
locals: local variables status: status code headers: headers.
Constructor Details
#initialize(env) ⇒ Controller
Returns a new instance of Controller.
18 19 20 21 22 |
# File 'lib/wings/controller.rb', line 18 def initialize(env) @env = env @request = Rack::Request.new(env) @params = request.params end |
Instance Attribute Details
#env ⇒ Object (readonly)
Returns the value of attribute env.
10 11 12 |
# File 'lib/wings/controller.rb', line 10 def env @env end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
10 11 12 |
# File 'lib/wings/controller.rb', line 10 def params @params end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
10 11 12 |
# File 'lib/wings/controller.rb', line 10 def request @request end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
10 11 12 |
# File 'lib/wings/controller.rb', line 10 def response @response end |
Class Method Details
.action(act, rp = {}) ⇒ Object
Respond to Rack The action will be used like a Rack app
14 15 16 |
# File 'lib/wings/controller.rb', line 14 def self.action(act, rp = {}) proc { |e| self.new(e).dispatch(act, rp) } end |
Instance Method Details
#dispatch(action, routing_params = {}) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/wings/controller.rb', line 24 def dispatch(action, routing_params = {}) @params.merge!(routing_params) self.send(action) if response [response.status, response.headers, response.body] else render(action) end end |
#render(template, **opts) ⇒ Object
- options for render
-
locals: local variables status: status code headers: headers
40 41 42 43 44 45 |
# File 'lib/wings/controller.rb', line 40 def render(template, **opts) raise 'You can only render once!' if @response v = View.new(params_for_view(template, opts)) @response = Rack::Response.new(v.text, v.status, v.headers) end |