Class: ActionController::Routing::OptionalFormatSegment
- Inherits:
-
DynamicSegment
- Object
- Segment
- DynamicSegment
- ActionController::Routing::OptionalFormatSegment
- Defined in:
- lib/action_controller/routing/segments.rb
Overview
The OptionalFormatSegment allows for any resource route to have an optional :format, which decreases the amount of routes created by 50%.
Constant Summary
Constants inherited from Segment
Segment::RESERVED_PCHAR, Segment::SAFE_PCHAR, Segment::UNSAFE_PCHAR
Instance Attribute Summary
Attributes inherited from DynamicSegment
Attributes inherited from Segment
Instance Method Summary collapse
- #extract_value ⇒ Object
-
#initialize(key = nil, options = {}) ⇒ OptionalFormatSegment
constructor
A new instance of OptionalFormatSegment.
- #interpolation_chunk ⇒ Object
-
#match_extraction(next_capture) ⇒ Object
the value should not include the period (.).
- #regexp_chunk ⇒ Object
- #to_s ⇒ Object
Methods inherited from DynamicSegment
#build_pattern, #default_regexp_chunk, #expiry_statement, #extraction_code, #local_name, #number_of_captures, #optionality_implied?, #regexp_has_modifiers?, #regexp_string, #string_structure, #value_check, #value_regexp
Methods inherited from Segment
#all_optionals_available_condition, #continue_string_structure, #extraction_code, #interpolation_statement, #number_of_captures, #optionality_implied?, #string_structure
Constructor Details
#initialize(key = nil, options = {}) ⇒ OptionalFormatSegment
Returns a new instance of OptionalFormatSegment.
312 313 314 |
# File 'lib/action_controller/routing/segments.rb', line 312 def initialize(key = nil, = {}) super(:format, {:optional => true}.merge()) end |
Instance Method Details
#extract_value ⇒ Object
328 329 330 |
# File 'lib/action_controller/routing/segments.rb', line 328 def extract_value "#{local_name} = options[:#{key}] && options[:#{key}].to_s.downcase" end |
#interpolation_chunk ⇒ Object
316 317 318 |
# File 'lib/action_controller/routing/segments.rb', line 316 def interpolation_chunk "." + super end |
#match_extraction(next_capture) ⇒ Object
the value should not include the period (.)
333 334 335 336 337 338 339 |
# File 'lib/action_controller/routing/segments.rb', line 333 def match_extraction(next_capture) %[ if (m = match[#{next_capture}]) params[:#{key}] = URI.unescape(m.from(1)) end ] end |
#regexp_chunk ⇒ Object
320 321 322 |
# File 'lib/action_controller/routing/segments.rb', line 320 def regexp_chunk '/|(\.[^/?\.]+)?' end |
#to_s ⇒ Object
324 325 326 |
# File 'lib/action_controller/routing/segments.rb', line 324 def to_s '(.:format)?' end |