class ActionDispatch::Journey::Route
def self.verb_matcher(verb)
def self.verb_matcher(verb) VerbMatchers::VERB_TO_CLASS.fetch(verb) do VerbMatchers::Unknown.new verb.to_s.dasherize.upcase end end
def dispatcher?
def dispatcher? @app.dispatcher? end
def eager_load!
def eager_load! path.eager_load! parts required_defaults nil end
def format(path_options)
def format(path_options) @path_formatter.evaluate path_options end
def glob?
def glob? path.ast.glob? end
def initialize(name:, app: nil, path:, constraints: {}, required_defaults: [], defaults: {}, request_method_match: nil, precedence: 0, scope_options: {}, internal: false)
+path+ is a path constraint.
#
def initialize(name:, app: nil, path:, constraints: {}, required_defaults: [], defaults: {}, request_method_match: nil, precedence: 0, scope_options: {}, internal: false) @name = name @app = app @path = path @request_method_match = request_method_match @constraints = constraints @defaults = defaults @required_defaults = nil @_required_defaults = required_defaults @required_parts = nil @parts = nil @precedence = precedence @path_formatter = @path.build_formatter @scope_options = scope_options @internal = internal @ast = @path.ast.root @path.ast.route = self end
def ip
def ip constraints[:ip] || // end
def match_verb(request)
def match_verb(request) @request_method_match.any? { |m| m.call request } end
def matches?(request)
def matches?(request) match_verb(request) && constraints.all? { |method, value| case value when Regexp, String value === request.send(method).to_s when Array value.include?(request.send(method)) when TrueClass request.send(method).present? when FalseClass request.send(method).blank? else value === request.send(method) end } end
def parts
def parts @parts ||= segments.map(&:to_sym) end
def required_default?(key)
def required_default?(key) @_required_defaults.include?(key) end
def required_defaults
def required_defaults @required_defaults ||= @defaults.dup.delete_if do |k, _| parts.include?(k) || !required_default?(k) end end
def required_keys
def required_keys required_parts + required_defaults.keys end
def required_parts
def required_parts @required_parts ||= path.required_names.map(&:to_sym) end
def requirements
will have {:controller=>"photos", :action=>"show", :id=>/[A-Z]\d{5}/}
:id => /[A-Z]\d{5}/
get 'photo/:id', :controller => 'photos', :action => 'show',
for a route, for example route
Needed for `bin/rails routes`. Picks up succinctly defined requirements
def requirements @defaults.merge(path.requirements).delete_if { |_, v| /.+?/m == v } end
def requires_matching_verb?
def requires_matching_verb? !@request_method_match.all? { |x| x == VerbMatchers::All } end
def score(supplied_keys)
def score(supplied_keys) path.required_names.each do |k| return -1 unless supplied_keys.include?(k) end (required_defaults.length * 2) + path.names.count { |k| supplied_keys.include?(k) } end
def segments
def segments path.names end
def verb
def verb verbs.join("|") end
def verbs
def verbs @request_method_match.map(&:verb) end