Class: ActionController::Routing::Segment
- Defined in:
- lib/action_controller/routing/segments.rb
Overview
:nodoc:
Direct Known Subclasses
Constant Summary collapse
- RESERVED_PCHAR =
':@&=+$,;'
- UNSAFE_PCHAR =
Regexp.new("[^#{URI::REGEXP::PATTERN::UNRESERVED}#{RESERVED_PCHAR}]", false, 'N').freeze
Instance Attribute Summary collapse
-
#is_optional ⇒ Object
(also: #optional?)
Returns the value of attribute is_optional.
Instance Method Summary collapse
-
#all_optionals_available_condition(prior_segments) ⇒ Object
Return an if condition that is true if all the prior segments can be generated.
-
#continue_string_structure(prior_segments) ⇒ Object
Continue generating string for the prior segments.
- #extraction_code ⇒ Object
-
#initialize ⇒ Segment
constructor
A new instance of Segment.
- #interpolation_chunk ⇒ Object
-
#interpolation_statement(prior_segments) ⇒ Object
Return a string interpolation statement for this segment and those before it.
-
#match_extraction(next_capture) ⇒ Object
Recognition.
-
#optionality_implied? ⇒ Boolean
Returns true if this segment is optional? because of a default.
- #string_structure(prior_segments) ⇒ Object
Constructor Details
#initialize ⇒ Segment
Returns a new instance of Segment.
10 11 12 |
# File 'lib/action_controller/routing/segments.rb', line 10 def initialize self.is_optional = false end |
Instance Attribute Details
#is_optional ⇒ Object Also known as: optional?
Returns the value of attribute is_optional.
7 8 9 |
# File 'lib/action_controller/routing/segments.rb', line 7 def is_optional @is_optional end |
Instance Method Details
#all_optionals_available_condition(prior_segments) ⇒ Object
Return an if condition that is true if all the prior segments can be generated. If there are no optional segments before this one, then nil is returned.
45 46 47 48 |
# File 'lib/action_controller/routing/segments.rb', line 45 def all_optionals_available_condition(prior_segments) optional_locals = prior_segments.collect { |s| s.local_name if s.optional? && s.respond_to?(:local_name) }.compact optional_locals.empty? ? nil : " if #{optional_locals * ' && '}" end |
#continue_string_structure(prior_segments) ⇒ Object
Continue generating string for the prior segments.
19 20 21 22 23 24 25 26 |
# File 'lib/action_controller/routing/segments.rb', line 19 def continue_string_structure(prior_segments) if prior_segments.empty? interpolation_statement(prior_segments) else new_priors = prior_segments[0..-2] prior_segments.last.string_structure(new_priors) end end |
#extraction_code ⇒ Object
14 15 16 |
# File 'lib/action_controller/routing/segments.rb', line 14 def extraction_code nil end |
#interpolation_chunk ⇒ Object
28 29 30 |
# File 'lib/action_controller/routing/segments.rb', line 28 def interpolation_chunk URI.escape(value, UNSAFE_PCHAR) end |
#interpolation_statement(prior_segments) ⇒ Object
Return a string interpolation statement for this segment and those before it.
33 34 35 36 37 |
# File 'lib/action_controller/routing/segments.rb', line 33 def interpolation_statement(prior_segments) chunks = prior_segments.collect { |s| s.interpolation_chunk } chunks << interpolation_chunk "\"#{chunks * ''}\"#{all_optionals_available_condition(prior_segments)}" end |
#match_extraction(next_capture) ⇒ Object
Recognition
52 53 54 |
# File 'lib/action_controller/routing/segments.rb', line 52 def match_extraction(next_capture) nil end |
#optionality_implied? ⇒ Boolean
Returns true if this segment is optional? because of a default. If so, then no warning will be emitted regarding this segment.
60 61 62 |
# File 'lib/action_controller/routing/segments.rb', line 60 def optionality_implied? false end |
#string_structure(prior_segments) ⇒ Object
39 40 41 |
# File 'lib/action_controller/routing/segments.rb', line 39 def string_structure(prior_segments) optional? ? continue_string_structure(prior_segments) : interpolation_statement(prior_segments) end |