Class: ActionDispatch::Journey::Route
Do not use. This class is for internal use only.
Relationships & Source Files | |
Namespace Children | |
Modules:
| |
Inherits: | Object |
Defined in: | actionpack/lib/action_dispatch/journey/route.rb |
Class Method Summary
Instance Attribute Summary
- #app readonly
- #ast readonly
-
#conditions
readonly
Alias for #constraints.
- #constraints (also: #conditions) readonly
- #defaults readonly
- #dispatcher? ⇒ Boolean readonly
- #glob? ⇒ Boolean readonly
- #internal readonly
- #name readonly
- #path readonly
- #precedence readonly
- #requires_matching_verb? ⇒ Boolean readonly
- #scope_options readonly
- #source_location readonly
Instance Method Summary
- #eager_load!
- #format(path_options)
- #ip
- #matches?(request) ⇒ Boolean
- #parts (also: #segment_keys)
- #required_default?(key) ⇒ Boolean
- #required_defaults
- #required_keys
- #required_parts
-
#requirements
Needed for
bin/rails routes
. - #score(supplied_keys)
-
#segment_keys
Alias for #parts.
- #segments
- #verb
- #match_verb(request) private
- #verbs private
Constructor Details
.new(name:, app: nil, path:, constraints: {}, required_defaults: [], defaults: {}, request_method_match: nil, precedence: 0, scope_options: {}, internal: false, source_location: nil) ⇒ Route
#path is a path constraint. #constraints is a hash of constraints to be applied to this route.
# File 'actionpack/lib/action_dispatch/journey/route.rb', line 58
def initialize(name:, app: nil, path:, constraints: {}, required_defaults: [], defaults: {}, request_method_match: nil, precedence: 0, scope_options: {}, internal: false, source_location: nil) @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 = @internal = internal @source_location = source_location @ast = @path.ast.root @path.ast.route = self end
Class Method Details
.verb_matcher(verb)
[ GitHub ]# File 'actionpack/lib/action_dispatch/journey/route.rb', line 49
def self.verb_matcher(verb) VerbMatchers::VERB_TO_CLASS.fetch(verb) do VerbMatchers::Unknown.new verb.to_s.dasherize.upcase end end
Instance Attribute Details
#app (readonly)
[ GitHub ]# File 'actionpack/lib/action_dispatch/journey/route.rb', line 9
attr_reader :app, :path, :defaults, :name, :precedence, :constraints, :internal, :, :ast, :source_location
#ast (readonly)
[ GitHub ]# File 'actionpack/lib/action_dispatch/journey/route.rb', line 9
attr_reader :app, :path, :defaults, :name, :precedence, :constraints, :internal, :, :ast, :source_location
#conditions (readonly)
Alias for #constraints.
# File 'actionpack/lib/action_dispatch/journey/route.rb', line 12
alias :conditions :constraints
#constraints (readonly) Also known as: #conditions
[ GitHub ]# File 'actionpack/lib/action_dispatch/journey/route.rb', line 9
attr_reader :app, :path, :defaults, :name, :precedence, :constraints, :internal, :, :ast, :source_location
#defaults (readonly)
[ GitHub ]# File 'actionpack/lib/action_dispatch/journey/route.rb', line 9
attr_reader :app, :path, :defaults, :name, :precedence, :constraints, :internal, :, :ast, :source_location
#dispatcher? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'actionpack/lib/action_dispatch/journey/route.rb', line 144
def dispatcher? @app.dispatcher? end
#glob? ⇒ Boolean
(readonly)
[ GitHub ]
#internal (readonly)
[ GitHub ]# File 'actionpack/lib/action_dispatch/journey/route.rb', line 9
attr_reader :app, :path, :defaults, :name, :precedence, :constraints, :internal, :, :ast, :source_location
#name (readonly)
[ GitHub ]# File 'actionpack/lib/action_dispatch/journey/route.rb', line 9
attr_reader :app, :path, :defaults, :name, :precedence, :constraints, :internal, :, :ast, :source_location
#path (readonly)
[ GitHub ]# File 'actionpack/lib/action_dispatch/journey/route.rb', line 9
attr_reader :app, :path, :defaults, :name, :precedence, :constraints, :internal, :, :ast, :source_location
#precedence (readonly)
[ GitHub ]# File 'actionpack/lib/action_dispatch/journey/route.rb', line 9
attr_reader :app, :path, :defaults, :name, :precedence, :constraints, :internal, :, :ast, :source_location
#requires_matching_verb? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'actionpack/lib/action_dispatch/journey/route.rb', line 170
def requires_matching_verb? !@request_method_match.all? { |x| x == VerbMatchers::All } end
#scope_options (readonly)
[ GitHub ]# File 'actionpack/lib/action_dispatch/journey/route.rb', line 9
attr_reader :app, :path, :defaults, :name, :precedence, :constraints, :internal, :, :ast, :source_location
#source_location (readonly)
[ GitHub ]# File 'actionpack/lib/action_dispatch/journey/route.rb', line 9
attr_reader :app, :path, :defaults, :name, :precedence, :constraints, :internal, :, :ast, :source_location
Instance Method Details
#eager_load!
[ GitHub ]# File 'actionpack/lib/action_dispatch/journey/route.rb', line 80
def eager_load! path.eager_load! parts required_defaults nil end
#format(path_options)
[ GitHub ]# File 'actionpack/lib/action_dispatch/journey/route.rb', line 122
def format( ) @path_formatter.evaluate end
#ip
[ GitHub ]# File 'actionpack/lib/action_dispatch/journey/route.rb', line 166
def ip constraints[:ip] || // end
#match_verb(request) (private)
[ GitHub ]# File 'actionpack/lib/action_dispatch/journey/route.rb', line 183
def match_verb(request) @request_method_match.any? { |m| m.call request } end
#matches?(request) ⇒ Boolean
# File 'actionpack/lib/action_dispatch/journey/route.rb', line 148
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
#parts Also known as: #segment_keys
[ GitHub ]# File 'actionpack/lib/action_dispatch/journey/route.rb', line 117
def parts @parts ||= segments.map(&:to_sym) end
#required_default?(key) ⇒ Boolean
# File 'actionpack/lib/action_dispatch/journey/route.rb', line 130
def required_default?(key) @_required_defaults.include?(key) end
#required_defaults
[ GitHub ]# File 'actionpack/lib/action_dispatch/journey/route.rb', line 134
def required_defaults @required_defaults ||= @defaults.dup.delete_if do |k, _| parts.include?(k) || !required_default?(k) end end
#required_keys
[ GitHub ]# File 'actionpack/lib/action_dispatch/journey/route.rb', line 105
def required_keys required_parts + required_defaults.keys end
#required_parts
[ GitHub ]# File 'actionpack/lib/action_dispatch/journey/route.rb', line 126
def required_parts @required_parts ||= path.required_names.map(&:to_sym) end
#requirements
Needed for bin/rails routes
. Picks up succinctly defined requirements for a route, for example route
get 'photo/:id', :controller => 'photos', :action => 'show',
:id => /[A-Z]\d{5}/
will have :action=>“show”, :[id=>/](A-Z){5
/} as requirements.
# File 'actionpack/lib/action_dispatch/journey/route.rb', line 95
def requirements @defaults.merge(path.requirements).delete_if { |_, v| /.+?/m == v } end
#score(supplied_keys)
[ GitHub ]# File 'actionpack/lib/action_dispatch/journey/route.rb', line 109
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
#segment_keys
Alias for #parts.
# File 'actionpack/lib/action_dispatch/journey/route.rb', line 120
alias :segment_keys :parts
#segments
[ GitHub ]# File 'actionpack/lib/action_dispatch/journey/route.rb', line 101
def segments path.names end
#verb
[ GitHub ]# File 'actionpack/lib/action_dispatch/journey/route.rb', line 174
def verb verbs.join("|") end
#verbs (private)
[ GitHub ]# File 'actionpack/lib/action_dispatch/journey/route.rb', line 179
def verbs @request_method_match.map(&:verb) end