Class: Flame::Router::Route
- Inherits:
-
Object
- Object
- Flame::Router::Route
- Defined in:
- lib/flame/router/route.rb
Overview
Class for Route in Router.routes
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#controller ⇒ Object
readonly
Returns the value of attribute controller.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Compare by: 1.
-
#==(other) ⇒ Object
Method for Routes comparison.
-
#compare_attributes(attrs) ⇒ Object
Compare attributes for ‘Router.find_route`.
- #freeze ⇒ Object
-
#initialize(controller, action, method, ctrl_path, action_path) ⇒ Route
constructor
A new instance of Route.
Constructor Details
#initialize(controller, action, method, ctrl_path, action_path) ⇒ Route
Returns a new instance of Route.
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/flame/router/route.rb', line 12 def initialize(controller, action, method, ctrl_path, action_path) @controller = controller @action = action @method = method.to_sym.upcase ## Make path by controller method with parameners action_path = Flame::Path.new(action_path).adapt(controller, action) ## Merge action path with controller path @path = Flame::Path.new(ctrl_path, action_path) Validators::RouteArgumentsValidator.new( @controller, action_path, @action ).valid? freeze end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
10 11 12 |
# File 'lib/flame/router/route.rb', line 10 def action @action end |
#controller ⇒ Object (readonly)
Returns the value of attribute controller.
10 11 12 |
# File 'lib/flame/router/route.rb', line 10 def controller @controller end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
10 11 12 |
# File 'lib/flame/router/route.rb', line 10 def method @method end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
10 11 12 |
# File 'lib/flame/router/route.rb', line 10 def path @path end |
Instance Method Details
#<=>(other) ⇒ Object
Compare by:
-
path parts count (more is matter);
-
args position (father is matter);
-
HTTP-method (default).
53 54 55 56 57 |
# File 'lib/flame/router/route.rb', line 53 def <=>(other) path_result = other.path <=> path return path_result unless path_result.zero? method <=> other.method end |
#==(other) ⇒ Object
Method for Routes comparison
41 42 43 44 45 46 47 |
# File 'lib/flame/router/route.rb', line 41 def ==(other) %i[controller action method path].reduce(true) do |result, method| result && ( public_send(method) == other.public_send(method) ) end end |
#compare_attributes(attrs) ⇒ Object
Compare attributes for ‘Router.find_route`
33 34 35 36 37 38 |
# File 'lib/flame/router/route.rb', line 33 def compare_attributes(attrs) attrs.each do |name, value| next true if compare_attribute(name, value) break false end end |
#freeze ⇒ Object
26 27 28 29 |
# File 'lib/flame/router/route.rb', line 26 def freeze @path.freeze super end |