Class: Flame::Controller
- Inherits:
-
Object
- Object
- Flame::Controller
- Extended by:
- Actions, Forwardable
- Includes:
- PathTo, Memery
- Defined in:
- lib/flame/controller.rb,
lib/flame/controller/actions.rb,
lib/flame/controller/cookies.rb,
lib/flame/controller/path_to.rb
Overview
Class initialize when Dispatcher found route with it For new request and response
Defined Under Namespace
Modules: Actions, PathTo Classes: Cookies
Class Attribute Summary collapse
-
.path_arguments ⇒ Object
Returns the value of attribute path_arguments.
Class Method Summary collapse
Instance Method Summary collapse
-
#attachment(filename = nil, disposition = :attachment) ⇒ Object
Set the Content-Disposition to “attachment” with the specified filename, instructing the user agents to prompt to save, and set Content-Type by filename.
-
#cookies ⇒ Object
Cookies object as Hash.
-
#initialize(dispatcher) ⇒ Controller
constructor
Initialize the controller for request execution.
-
#redirect(*args) ⇒ Object
Redirect for response.
-
#view(path = nil, options = {}) ⇒ String
(also: #render)
Render a template with
Flame::Render(based on Tilt-engine).
Methods included from Actions
actions, inherit_actions, with_actions
Methods included from PathTo
#path_to, #path_to_back, #url_to
Constructor Details
#initialize(dispatcher) ⇒ Controller
Initialize the controller for request execution
57 58 59 |
# File 'lib/flame/controller.rb', line 57 def initialize(dispatcher) @dispatcher = dispatcher end |
Class Attribute Details
.path_arguments ⇒ Object
Returns the value of attribute path_arguments.
32 33 34 |
# File 'lib/flame/controller.rb', line 32 def path_arguments @path_arguments end |
Class Method Details
.path ⇒ Object
34 35 36 37 38 |
# File 'lib/flame/controller.rb', line 34 def path return self::PATH if const_defined?(:PATH) default_path end |
Instance Method Details
#attachment(filename = nil, disposition = :attachment) ⇒ Object
Set the Content-Disposition to “attachment” with the specified filename, instructing the user agents to prompt to save, and set Content-Type by filename.
115 116 117 118 119 120 121 122 123 |
# File 'lib/flame/controller.rb', line 115 def (filename = nil, disposition = :attachment) content_dis = 'Content-Disposition' response[content_dis] = disposition.to_s return unless filename response[content_dis] += "; filename=\"#{File.basename(filename)}\"" ext = File.extname(filename) response.content_type = ext unless ext.empty? end |
#cookies ⇒ Object
Cookies object as Hash
62 63 64 |
# File 'lib/flame/controller.rb', line 62 memoize def Cookies.new(request., response) end |
#redirect(path, status) ⇒ nil #redirect(uri, status) ⇒ nil #redirect(*args, status) ⇒ nil
Redirect for response
96 97 98 99 100 101 102 103 104 |
# File 'lib/flame/controller.rb', line 96 def redirect(*args) args[0] = args.first.to_s if args.first.is_a? URI unless args.first.is_a? String path_to_args_range = 0..(args.last.is_a?(Integer) ? -2 : -1) args[path_to_args_range] = path_to(*args[path_to_args_range]) end response.redirect(*args) status end |
#view(path = nil, options = {}) ⇒ String Also known as: render
Render a template with Flame::Render (based on Tilt-engine)
129 130 131 132 133 134 135 136 137 138 |
# File 'lib/flame/controller.rb', line 129 def view(path = nil, = {}, &) cache = .delete(:cache) cache = config[:environment] == 'production' if cache.nil? template = Flame::Render.new( self, path || caller_locations(1, 1)[0].base_label.to_sym, ) template.render(cache: cache, &) end |