Class: ActionController::Routing::StaticSegment

Inherits:
Segment show all
Defined in:
lib/action_controller/routing.rb

Direct Known Subclasses

DividerSegment

Instance Attribute Summary collapse

Attributes inherited from Segment

#is_optional

Instance Method Summary collapse

Methods inherited from Segment

#all_optionals_available_condition, #continue_string_structure, #extraction_code, #interpolation_statement, #match_extraction, #optionality_implied?, #string_structure

Constructor Details

#initialize(value = nil) ⇒ StaticSegment

Returns a new instance of StaticSegment.



598
599
600
601
# File 'lib/action_controller/routing.rb', line 598

def initialize(value = nil)
  super()
  self.value = value
end

Instance Attribute Details

#rawObject Also known as: raw?

Returns the value of attribute raw.



595
596
597
# File 'lib/action_controller/routing.rb', line 595

def raw
  @raw
end

#valueObject

Returns the value of attribute value.



595
596
597
# File 'lib/action_controller/routing.rb', line 595

def value
  @value
end

Instance Method Details

#build_pattern(pattern) ⇒ Object



612
613
614
615
616
617
618
619
620
621
# File 'lib/action_controller/routing.rb', line 612

def build_pattern(pattern)
  escaped = Regexp.escape(value)
  if optional? && ! pattern.empty?
    "(?:#{Regexp.optionalize escaped}\\Z|#{escaped}#{Regexp.unoptionalize pattern})"
  elsif optional?
    Regexp.optionalize escaped
  else
    escaped + pattern
  end
end

#interpolation_chunkObject



603
604
605
# File 'lib/action_controller/routing.rb', line 603

def interpolation_chunk
  raw? ? value : CGI.escape(value)
end

#regexp_chunkObject



607
608
609
610
# File 'lib/action_controller/routing.rb', line 607

def regexp_chunk
  chunk = Regexp.escape value
  optional? ? Regexp.optionalize(chunk) : chunk
end

#to_sObject



623
624
625
# File 'lib/action_controller/routing.rb', line 623

def to_s
  value
end