public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Extract ActiveSupport::TypedArray class to ensure an array is all of the same 
type [#673 state:resolved]
josh (author)
Tue Jul 22 09:12:16 -0700 2008
commit  2681685450631238511cfc3c2f0fa044c1f8033a
tree    2414319c504d25ece84a8cfdce5f2f6c10b13fc8
parent  bc5896e708bf8070835bebe61de03b701fa5e6f7
...
1
2
 
3
4
5
...
25
26
27
28
 
29
30
31
...
38
39
40
 
 
 
 
41
42
43
...
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
...
97
98
99
100
101
102
103
104
105
106
...
1
 
2
3
4
5
...
25
26
27
 
28
29
30
31
...
38
39
40
41
42
43
44
45
46
47
...
71
72
73
 
 
 
 
74
75
76
77
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
79
80
...
83
84
85
 
 
 
 
 
86
87
0
@@ -1,5 +1,5 @@
0
 module ActionView #:nodoc:
0
-  class PathSet < Array #:nodoc:
0
+  class PathSet < ActiveSupport::TypedArray #:nodoc:
0
     def self.type_cast(obj)
0
       if obj.is_a?(String)
0
         if Base.warn_cache_misses && defined?(Rails) && Rails.initialized?
0
@@ -25,7 +25,7 @@ module ActionView #:nodoc:
0
       end
0
 
0
       attr_reader :path, :paths
0
-      delegate :to_s, :to_str, :inspect, :to => :path
0
+      delegate :to_s, :to_str, :hash, :inspect, :to => :path
0
 
0
       def initialize(path)
0
         raise ArgumentError, "path already is a Path class" if path.is_a?(Path)
0
@@ -38,6 +38,10 @@ module ActionView #:nodoc:
0
         to_str == path.to_str
0
       end
0
 
0
+      def eql?(path)
0
+        to_str == path.to_str
0
+      end
0
+
0
       def [](path)
0
         @paths[path]
0
       end
0
@@ -67,28 +71,10 @@ module ActionView #:nodoc:
0
         end
0
     end
0
 
0
-    def initialize(*args)
0
-      super(*args).map! { |obj| self.class.type_cast(obj) }
0
-    end
0
-
0
     def reload!
0
       each { |path| path.reload! }
0
     end
0
 
0
-    def <<(obj)
0
-      super(self.class.type_cast(obj))
0
-    end
0
-
0
-    def push(*objs)
0
-      delete_paths!(objs)
0
-      super(*objs.map { |obj| self.class.type_cast(obj) })
0
-    end
0
-
0
-    def unshift(*objs)
0
-      delete_paths!(objs)
0
-      super(*objs.map { |obj| self.class.type_cast(obj) })
0
-    end
0
-
0
     def [](template_path)
0
       each do |path|
0
         if template = path[template_path]
0
@@ -97,10 +83,5 @@ module ActionView #:nodoc:
0
       end
0
       nil
0
     end
0
-
0
-    private
0
-      def delete_paths!(paths)
0
-        paths.each { |p1| delete_if { |p2| p1.to_s == p2.to_s } }
0
-      end
0
   end
0
 end
...
54
55
56
57
58
59
60
 
61
62
63
...
68
69
70
71
72
73
74
 
75
76
77
...
54
55
56
 
 
 
 
57
58
59
60
...
65
66
67
 
 
 
 
68
69
70
71
0
@@ -54,10 +54,7 @@ class ViewLoadPathsTest < Test::Unit::TestCase
0
     assert_equal [FIXTURE_LOAD_PATH, 'foo', 'bar', 'baz'], @controller.view_paths
0
 
0
     @controller.append_view_path(FIXTURE_LOAD_PATH)
0
-    assert_equal ['foo', 'bar', 'baz', FIXTURE_LOAD_PATH], @controller.view_paths
0
-
0
-    @controller.append_view_path([FIXTURE_LOAD_PATH])
0
-    assert_equal ['foo', 'bar', 'baz', FIXTURE_LOAD_PATH], @controller.view_paths
0
+    assert_equal [FIXTURE_LOAD_PATH, 'foo', 'bar', 'baz', FIXTURE_LOAD_PATH], @controller.view_paths
0
   end
0
 
0
   def test_controller_prepends_view_path_correctly
0
@@ -68,10 +65,7 @@ class ViewLoadPathsTest < Test::Unit::TestCase
0
     assert_equal ['foo', 'bar', 'baz', FIXTURE_LOAD_PATH], @controller.view_paths
0
 
0
     @controller.prepend_view_path(FIXTURE_LOAD_PATH)
0
-    assert_equal [FIXTURE_LOAD_PATH, 'foo', 'bar', 'baz'], @controller.view_paths
0
-
0
-    @controller.prepend_view_path([FIXTURE_LOAD_PATH])
0
-    assert_equal [FIXTURE_LOAD_PATH, 'foo', 'bar', 'baz'], @controller.view_paths
0
+    assert_equal [FIXTURE_LOAD_PATH, 'foo', 'bar', 'baz', FIXTURE_LOAD_PATH], @controller.view_paths
0
   end
0
 
0
   def test_template_appends_view_path_correctly
...
39
40
41
 
42
43
44
...
39
40
41
42
43
44
45
0
@@ -39,6 +39,7 @@ require 'active_support/cache'
0
 require 'active_support/dependencies'
0
 require 'active_support/deprecation'
0
 
0
+require 'active_support/typed_array'
0
 require 'active_support/ordered_hash'
0
 require 'active_support/ordered_options'
0
 require 'active_support/option_merger'

Comments