Class: ActionController::Routing::StaticSegment

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

Overview

:nodoc:

Direct Known Subclasses

DividerSegment

Constant Summary

Constants inherited from Segment

ActionController::Routing::Segment::RESERVED_PCHAR, ActionController::Routing::Segment::SAFE_PCHAR, ActionController::Routing::Segment::UNSAFE_PCHAR

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, options = {}) ⇒ StaticSegment



75
76
77
78
79
80
# File 'lib/action_controller/routing/segments.rb', line 75

def initialize(value = nil, options = {})
  super()
  @value = value
  @raw = options[:raw] if options.key?(:raw)
  @is_optional = options[:optional] if options.key?(:optional)
end

Instance Attribute Details

#rawObject (readonly) Also known as: raw?

Returns the value of attribute raw.



72
73
74
# File 'lib/action_controller/routing/segments.rb', line 72

def raw
  @raw
end

#valueObject (readonly)

Returns the value of attribute value.



72
73
74
# File 'lib/action_controller/routing/segments.rb', line 72

def value
  @value
end

Instance Method Details

#build_pattern(pattern) ⇒ Object



95
96
97
98
99
100
101
102
103
104
# File 'lib/action_controller/routing/segments.rb', line 95

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



82
83
84
# File 'lib/action_controller/routing/segments.rb', line 82

def interpolation_chunk
  raw? ? value : super
end

#number_of_capturesObject



91
92
93
# File 'lib/action_controller/routing/segments.rb', line 91

def number_of_captures
  0
end

#regexp_chunkObject



86
87
88
89
# File 'lib/action_controller/routing/segments.rb', line 86

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

#to_sObject



106
107
108
# File 'lib/action_controller/routing/segments.rb', line 106

def to_s
  value
end