Class: Hibana::Controller
- Inherits:
-
Object
- Object
- Hibana::Controller
- Defined in:
- lib/hibana/controller.rb
Constant Summary collapse
- DEFAULT_RESPONSE_BODY =
''
- DEFAULT_RESPONSE_STATUS =
200
Instance Attribute Summary collapse
- #response ⇒ Rack::Response readonly
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(env:) ⇒ Controller
constructor
A new instance of Controller.
- #parameters ⇒ Hash{Symbol => String}
- #path_parameters ⇒ Hash{Symbol => String}
- #request ⇒ Rack::Request
- #to_rack_spec_response ⇒ Array
Constructor Details
#initialize(env:) ⇒ Controller
Returns a new instance of Controller.
22 23 24 25 26 27 28 |
# File 'lib/hibana/controller.rb', line 22 def initialize(env:) @env = env @response = ::Rack::Response.new( DEFAULT_RESPONSE_BODY, DEFAULT_RESPONSE_STATUS ) end |
Instance Attribute Details
#response ⇒ Rack::Response (readonly)
19 20 21 |
# File 'lib/hibana/controller.rb', line 19 def response @response end |
Class Method Details
.call(env) ⇒ Array
11 12 13 14 15 |
# File 'lib/hibana/controller.rb', line 11 def call(env) controller = new(env: env) controller.call controller.to_rack_spec_response end |
Instance Method Details
#call ⇒ Object
30 31 32 |
# File 'lib/hibana/controller.rb', line 30 def call raise ::NotImplementedError end |
#parameters ⇒ Hash{Symbol => String}
TODO:
41 42 43 |
# File 'lib/hibana/controller.rb', line 41 def parameters path_parameters end |
#path_parameters ⇒ Hash{Symbol => String}
35 36 37 |
# File 'lib/hibana/controller.rb', line 35 def path_parameters request.env['router.params'] end |
#request ⇒ Rack::Request
46 47 48 |
# File 'lib/hibana/controller.rb', line 46 def request @request ||= ::Rack::Request.new(@env) end |
#to_rack_spec_response ⇒ Array
52 53 54 55 56 57 58 |
# File 'lib/hibana/controller.rb', line 52 def to_rack_spec_response [ @response.status, @response.headers, @response.body, ] end |