Class: Kangaru::Controller
- Inherits:
-
Object
- Object
- Kangaru::Controller
- Extended by:
- Forwardable
- Defined in:
- lib/kangaru/controller.rb
Constant Summary collapse
- SUFFIX =
"Controller".freeze
Instance Attribute Summary collapse
-
#request ⇒ Object
readonly
Returns the value of attribute request.
Class Method Summary collapse
-
.path ⇒ Object
Returns the partial path for the controller based on the class name.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(request) ⇒ Controller
constructor
A new instance of Controller.
- #target_id ⇒ Object
Constructor Details
#initialize(request) ⇒ Controller
Returns a new instance of Controller.
11 12 13 |
# File 'lib/kangaru/controller.rb', line 11 def initialize(request) @request = request end |
Instance Attribute Details
#request ⇒ Object (readonly)
Returns the value of attribute request.
9 10 11 |
# File 'lib/kangaru/controller.rb', line 9 def request @request end |
Class Method Details
.path ⇒ Object
Returns the partial path for the controller based on the class name. The first module namespace is removed as this is either Kangaru or the target gem namespace. Used to infer the location of view files.
24 25 26 |
# File 'lib/kangaru/controller.rb', line 24 def self.path name&.delete_suffix(SUFFIX)&.gsub(/^.*?::/, "")&.to_snakecase || raise end |
Instance Method Details
#execute ⇒ Object
15 16 17 18 19 |
# File 'lib/kangaru/controller.rb', line 15 def execute return unless public_send(request.action) renderer_for(request.action.to_s).render(binding) end |
#target_id ⇒ Object
30 31 32 |
# File 'lib/kangaru/controller.rb', line 30 def target_id request.id end |