Class: Flame::Route
- Inherits:
-
Object
- Object
- Flame::Route
- Defined in:
- lib/flame/route.rb
Overview
Class for Route in Router.routes
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
Instance Method Summary collapse
- #[](attribute) ⇒ Object
-
#assign_arguments(args = {}) ⇒ Object
Assign arguments to path for
Controller.path_to. -
#compare_attributes(attrs) ⇒ Object
Compare attributes for
Router.find_route. -
#execute(dispatcher) ⇒ Object
Execute by Application.call.
-
#initialize(attrs = {}) ⇒ Route
constructor
A new instance of Route.
Constructor Details
#initialize(attrs = {}) ⇒ Route
Returns a new instance of Route.
6 7 8 9 10 |
# File 'lib/flame/route.rb', line 6 def initialize(attrs = {}) @attributes = attrs.merge( path_parts: attrs[:path].to_s.split('/').reject(&:empty?) ) end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
4 5 6 |
# File 'lib/flame/route.rb', line 4 def attributes @attributes end |
Instance Method Details
#[](attribute) ⇒ Object
12 13 14 |
# File 'lib/flame/route.rb', line 12 def [](attribute) @attributes[attribute] end |
#assign_arguments(args = {}) ⇒ Object
Assign arguments to path for Controller.path_to
25 26 27 28 29 |
# File 'lib/flame/route.rb', line 25 def assign_arguments(args = {}) self[:path_parts] .map { |path_part| assign_argument(path_part, args) } .unshift('').join('/').gsub(%r{\/{2,}}, '/') end |
#compare_attributes(attrs) ⇒ Object
Compare attributes for Router.find_route
17 18 19 20 21 22 |
# File 'lib/flame/route.rb', line 17 def compare_attributes(attrs) attrs.each do |name, value| next true if compare_attribute(name, value) break false end end |
#execute(dispatcher) ⇒ Object
Execute by Application.call
32 33 34 35 36 37 |
# File 'lib/flame/route.rb', line 32 def execute(dispatcher) ctrl = self[:controller].new(dispatcher) dispatcher.params.merge!(arguments(dispatcher.request.path_parts)) dispatcher.router.find_befores(self).each { |before| ctrl.send(before) } ctrl.send(self[:action], *arranged_arguments) end |