Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Updated Route and StaticSegment initializers - non backwards-compatib…

…le with Rails2.1.1
  • Loading branch information...
commit 07c8ca6bdbcb960da745dde8e80467f65377772c 1 parent a8f30ba
@raul authored
View
19 SampleApp/vendor/plugins/translate_routes/lib/translate_routes.rb
@@ -117,9 +117,8 @@ def self.translate_static_segments(route, dictionary)
segments = []
route.segments.each do |s|
if s.instance_of?(StaticSegment)
- new_segment = StaticSegment.new
- new_segment.value = dictionary[s.value] || s.value.dup
- new_segment.is_optional = s.is_optional
+ value = dictionary[s.value] || s.value.dup
+ new_segment = StaticSegment.new(value, :raw => s.raw, :optional => s.optional?)
else
new_segment = s.dup # just reference the original
end
@@ -132,14 +131,10 @@ def self.lang_segments(orig, lang, dictionary)
return translate_static_segments(orig, dictionary) unless add_prefix?(lang)
# divider ('/')
- divider = DividerSegment.new
- divider.value = orig.segments.first.value
- divider.is_optional = false # la prueba
+ divider = DividerSegment.new(orig.segments.first.value, :optionals => false)
# static ('es')
- static = StaticSegment.new
- static.value = lang
- static.is_optional = false
+ static = StaticSegment.new(lang, :optional => false)
[divider, static] + translate_static_segments(orig, dictionary)
end
@@ -153,11 +148,7 @@ def self.translate_route_by_lang(orig, lang, dictionary, orig_name=nil)
requirements = lang_requirements(orig, lang)
conditions = orig.conditions
- r = Route.new
- r.segments = segments
- r.requirements = requirements
- r.conditions = conditions
- r
+ Route.new(segments, requirements, conditions).freeze
end
def self.translate_route(route, dictionaries, route_name = nil)
View
19 lib/translate_routes.rb
@@ -117,9 +117,8 @@ def self.translate_static_segments(route, dictionary)
segments = []
route.segments.each do |s|
if s.instance_of?(StaticSegment)
- new_segment = StaticSegment.new
- new_segment.value = dictionary[s.value] || s.value.dup
- new_segment.is_optional = s.is_optional
+ value = dictionary[s.value] || s.value.dup
+ new_segment = StaticSegment.new(value, :raw => s.raw, :optional => s.optional?)
else
new_segment = s.dup # just reference the original
end
@@ -132,14 +131,10 @@ def self.lang_segments(orig, lang, dictionary)
return translate_static_segments(orig, dictionary) unless add_prefix?(lang)
# divider ('/')
- divider = DividerSegment.new
- divider.value = orig.segments.first.value
- divider.is_optional = false # la prueba
+ divider = DividerSegment.new(orig.segments.first.value, :optionals => false)
# static ('es')
- static = StaticSegment.new
- static.value = lang
- static.is_optional = false
+ static = StaticSegment.new(lang, :optional => false)
[divider, static] + translate_static_segments(orig, dictionary)
end
@@ -153,11 +148,7 @@ def self.translate_route_by_lang(orig, lang, dictionary, orig_name=nil)
requirements = lang_requirements(orig, lang)
conditions = orig.conditions
- r = Route.new
- r.segments = segments
- r.requirements = requirements
- r.conditions = conditions
- r
+ Route.new(segments, requirements, conditions).freeze
end
def self.translate_route(route, dictionaries, route_name = nil)
Please sign in to comment.
Something went wrong with that request. Please try again.