class Flame::Router::Route
Class for Route
in Router.routes
Attributes
action[R]
controller[R]
method[R]
path[R]
Public Class Methods
new(controller, action, method, ctrl_path, action_path)
click to toggle source
# 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
Public Instance Methods
<=>(other)
click to toggle source
Compare by:
-
path parts count (more is matter);
-
args position (father is matter);
-
HTTP-method (default).
# 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)
click to toggle source
Method for Routes comparison
# 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)
click to toggle source
Compare attributes for `Router.find_route` @param attrs [Hash] Hash of attributes for comparing
# 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()
click to toggle source
Calls superclass method
# File lib/flame/router/route.rb, line 26 def freeze @path.freeze super end
Private Instance Methods
compare_attribute(name, value)
click to toggle source
Helpers for `compare_attributes`
# File lib/flame/router/route.rb, line 62 def compare_attribute(name, value) case name when :method compare_method(value) when :path path.match? value else send(name) == value end end
compare_method(request_method)
click to toggle source
# File lib/flame/router/route.rb, line 73 def compare_method(request_method) request_method = request_method.upcase.to_sym request_method = :GET if request_method == :HEAD method.upcase.to_sym == request_method end