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
-
#arrange_arguments(args = {}) ⇒ Object
Arguments in order as parameters of method of controller.
-
#assign_arguments(args = {}) ⇒ Object
Assign arguments to path for
Controller.path_to. -
#compare_attributes(attrs) ⇒ Object
Compare attributes for
Router.find_route. -
#execute(app) ⇒ 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 |
# File 'lib/flame/route.rb', line 6 def initialize(attrs = {}) @attributes = attrs 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
10 11 12 |
# File 'lib/flame/route.rb', line 10 def [](attribute) @attributes[attribute] end |
#arrange_arguments(args = {}) ⇒ Object
Arguments in order as parameters of method of controller
15 16 17 18 19 20 |
# File 'lib/flame/route.rb', line 15 def arrange_arguments(args = {}) self[:controller].instance_method(self[:action]).parameters .each_with_object([]) do |par, arr| arr << args[par[1]] if par[0] == :req || args[par[1]] end end |
#assign_arguments(args = {}) ⇒ Object
Assign arguments to path for Controller.path_to
31 32 33 34 35 |
# File 'lib/flame/route.rb', line 31 def assign_arguments(args = {}) extract_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
23 24 25 26 27 28 |
# File 'lib/flame/route.rb', line 23 def compare_attributes(attrs) attrs.each do |name, value| next true if compare_attribute(name, value) break false end end |
#execute(app) ⇒ Object
Execute by Application.call
38 39 40 41 42 43 |
# File 'lib/flame/route.rb', line 38 def execute(app) ctrl = self[:controller].new(app) args = extract_arguments(app.request.path_info) app.params.merge!(args) ctrl.send(self[:action], *arrange_arguments(args)) end |