aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/routing/segments.rb
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2008-07-28 13:41:42 -0500
committerJoshua Peek <josh@joshpeek.com>2008-07-28 13:41:42 -0500
commita5db1488251304ec93256654859b430148f0c506 (patch)
tree92b454caa321d55365710eb02696c071135b6dd9 /actionpack/lib/action_controller/routing/segments.rb
parente0513e33c4da60255e7c1aa71babcc9414f26858 (diff)
downloadrails-a5db1488251304ec93256654859b430148f0c506.tar.gz
rails-a5db1488251304ec93256654859b430148f0c506.tar.bz2
rails-a5db1488251304ec93256654859b430148f0c506.zip
Prepare Route#generate and Route#recognize early. Also refactor segments a bit to try to make immutable.
Diffstat (limited to 'actionpack/lib/action_controller/routing/segments.rb')
-rw-r--r--actionpack/lib/action_controller/routing/segments.rb29
1 files changed, 17 insertions, 12 deletions
diff --git a/actionpack/lib/action_controller/routing/segments.rb b/actionpack/lib/action_controller/routing/segments.rb
index 18e76b6b82..75784c3b78 100644
--- a/actionpack/lib/action_controller/routing/segments.rb
+++ b/actionpack/lib/action_controller/routing/segments.rb
@@ -4,11 +4,12 @@ module ActionController
RESERVED_PCHAR = ':@&=+$,;'
UNSAFE_PCHAR = Regexp.new("[^#{URI::REGEXP::PATTERN::UNRESERVED}#{RESERVED_PCHAR}]", false, 'N').freeze
+ # TODO: Convert :is_optional accessor to read only
attr_accessor :is_optional
alias_method :optional?, :is_optional
def initialize
- self.is_optional = false
+ @is_optional = false
end
def extraction_code
@@ -63,12 +64,14 @@ module ActionController
end
class StaticSegment < Segment #:nodoc:
- attr_accessor :value, :raw
+ attr_reader :value, :raw
alias_method :raw?, :raw
- def initialize(value = nil)
+ def initialize(value = nil, options = {})
super()
- self.value = value
+ @value = value
+ @raw = options[:raw] if options.key?(:raw)
+ @is_optional = options[:optional] if options.key?(:optional)
end
def interpolation_chunk
@@ -97,10 +100,8 @@ module ActionController
end
class DividerSegment < StaticSegment #:nodoc:
- def initialize(value = nil)
- super(value)
- self.raw = true
- self.is_optional = true
+ def initialize(value = nil, options = {})
+ super(value, {:raw => true, :optional => true}.merge(options))
end
def optionality_implied?
@@ -109,13 +110,17 @@ module ActionController
end
class DynamicSegment < Segment #:nodoc:
- attr_accessor :key, :default, :regexp
+ attr_reader :key
+
+ # TODO: Convert these accessors to read only
+ attr_accessor :default, :regexp
def initialize(key = nil, options = {})
super()
- self.key = key
- self.default = options[:default] if options.key? :default
- self.is_optional = true if options[:optional] || options.key?(:default)
+ @key = key
+ @default = options[:default] if options.key?(:default)
+ @regexp = options[:regexp] if options.key?(:regexp)
+ @is_optional = true if options[:optional] || options.key?(:default)
end
def to_s