Class: Flame::Controller
- Inherits:
-
Object
- Object
- Flame::Controller
- Defined in:
- lib/flame/controller.rb
Overview
Class initialize when Dispatcher found route with it For new request and response
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(dispatcher) ⇒ Controller
constructor
A new instance of Controller.
-
#method_missing(m, *args, &block) ⇒ Object
Helpers from Flame::Dispatcher.
-
#path_to(*args) ⇒ Object
Helpers.
- #redirect(*params) ⇒ Object
- #view(path = nil, options = {}) ⇒ Object (also: #render)
Constructor Details
#initialize(dispatcher) ⇒ Controller
Returns a new instance of Controller.
8 9 10 |
# File 'lib/flame/controller.rb', line 8 def initialize(dispatcher) @dispatcher = dispatcher end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
Helpers from Flame::Dispatcher
35 36 37 38 |
# File 'lib/flame/controller.rb', line 35 def method_missing(m, *args, &block) return super unless @dispatcher.respond_to?(m) @dispatcher.send(m, *args, &block) end |
Class Method Details
.default_path(last = false) ⇒ Object
43 44 45 46 47 |
# File 'lib/flame/controller.rb', line 43 def default_path(last = false) (name.split('::').last.underscore.split('_') - %w(index controller ctrl)) .join('/').split('/') .unshift(nil)[(last ? -1 : 0)..-1].join('/') end |
Instance Method Details
#path_to(*args) ⇒ Object
Helpers
13 14 15 16 |
# File 'lib/flame/controller.rb', line 13 def path_to(*args) args.unshift self.class if args[0].is_a? Symbol @dispatcher.path_to(*args) end |
#redirect(*params) ⇒ Object
18 19 20 21 22 |
# File 'lib/flame/controller.rb', line 18 def redirect(*params) response.redirect( params[0].is_a?(String) ? params[0] : path_to(*params) ) end |
#view(path = nil, options = {}) ⇒ Object Also known as: render
24 25 26 27 28 29 30 31 |
# File 'lib/flame/controller.rb', line 24 def view(path = nil, = {}) template = Flame::Render.new( self, (path || caller_locations(1, 1)[0].label.to_sym), ) template.render(cache: config[:environment] == 'production') end |