diff options
author | Joshua Peek <josh@joshpeek.com> | 2008-07-22 11:12:16 -0500 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2008-07-22 11:12:16 -0500 |
commit | 2681685450631238511cfc3c2f0fa044c1f8033a (patch) | |
tree | 2414319c504d25ece84a8cfdce5f2f6c10b13fc8 /actionpack | |
parent | bc5896e708bf8070835bebe61de03b701fa5e6f7 (diff) | |
download | rails-2681685450631238511cfc3c2f0fa044c1f8033a.tar.gz rails-2681685450631238511cfc3c2f0fa044c1f8033a.tar.bz2 rails-2681685450631238511cfc3c2f0fa044c1f8033a.zip |
Extract ActiveSupport::TypedArray class to ensure an array is all of the same type [#673 state:resolved]
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_view/paths.rb | 31 | ||||
-rw-r--r-- | actionpack/test/controller/view_paths_test.rb | 10 |
2 files changed, 8 insertions, 33 deletions
diff --git a/actionpack/lib/action_view/paths.rb b/actionpack/lib/action_view/paths.rb index 78548d4aa2..9cb50ab4f8 100644 --- a/actionpack/lib/action_view/paths.rb +++ b/actionpack/lib/action_view/paths.rb @@ -1,5 +1,5 @@ module ActionView #:nodoc: - class PathSet < Array #:nodoc: + class PathSet < ActiveSupport::TypedArray #:nodoc: def self.type_cast(obj) if obj.is_a?(String) if Base.warn_cache_misses && defined?(Rails) && Rails.initialized? @@ -25,7 +25,7 @@ module ActionView #:nodoc: end attr_reader :path, :paths - delegate :to_s, :to_str, :inspect, :to => :path + delegate :to_s, :to_str, :hash, :inspect, :to => :path def initialize(path) raise ArgumentError, "path already is a Path class" if path.is_a?(Path) @@ -38,6 +38,10 @@ module ActionView #:nodoc: to_str == path.to_str end + def eql?(path) + to_str == path.to_str + end + def [](path) @paths[path] end @@ -67,28 +71,10 @@ module ActionView #:nodoc: end end - def initialize(*args) - super(*args).map! { |obj| self.class.type_cast(obj) } - end - def reload! each { |path| path.reload! } end - def <<(obj) - super(self.class.type_cast(obj)) - end - - def push(*objs) - delete_paths!(objs) - super(*objs.map { |obj| self.class.type_cast(obj) }) - end - - def unshift(*objs) - delete_paths!(objs) - super(*objs.map { |obj| self.class.type_cast(obj) }) - end - def [](template_path) each do |path| if template = path[template_path] @@ -97,10 +83,5 @@ module ActionView #:nodoc: end nil end - - private - def delete_paths!(paths) - paths.each { |p1| delete_if { |p2| p1.to_s == p2.to_s } } - end end end diff --git a/actionpack/test/controller/view_paths_test.rb b/actionpack/test/controller/view_paths_test.rb index 85fa58a45b..b859a92cbd 100644 --- a/actionpack/test/controller/view_paths_test.rb +++ b/actionpack/test/controller/view_paths_test.rb @@ -54,10 +54,7 @@ class ViewLoadPathsTest < Test::Unit::TestCase assert_equal [FIXTURE_LOAD_PATH, 'foo', 'bar', 'baz'], @controller.view_paths @controller.append_view_path(FIXTURE_LOAD_PATH) - assert_equal ['foo', 'bar', 'baz', FIXTURE_LOAD_PATH], @controller.view_paths - - @controller.append_view_path([FIXTURE_LOAD_PATH]) - assert_equal ['foo', 'bar', 'baz', FIXTURE_LOAD_PATH], @controller.view_paths + assert_equal [FIXTURE_LOAD_PATH, 'foo', 'bar', 'baz', FIXTURE_LOAD_PATH], @controller.view_paths end def test_controller_prepends_view_path_correctly @@ -68,10 +65,7 @@ class ViewLoadPathsTest < Test::Unit::TestCase assert_equal ['foo', 'bar', 'baz', FIXTURE_LOAD_PATH], @controller.view_paths @controller.prepend_view_path(FIXTURE_LOAD_PATH) - assert_equal [FIXTURE_LOAD_PATH, 'foo', 'bar', 'baz'], @controller.view_paths - - @controller.prepend_view_path([FIXTURE_LOAD_PATH]) - assert_equal [FIXTURE_LOAD_PATH, 'foo', 'bar', 'baz'], @controller.view_paths + assert_equal [FIXTURE_LOAD_PATH, 'foo', 'bar', 'baz', FIXTURE_LOAD_PATH], @controller.view_paths end def test_template_appends_view_path_correctly |