aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support.rb1
-rw-r--r--activesupport/lib/active_support/callbacks.rb21
-rw-r--r--activesupport/lib/active_support/core_ext/duplicable.rb6
-rw-r--r--activesupport/lib/active_support/typed_array.rb31
-rw-r--r--activesupport/test/callbacks_test.rb8
-rw-r--r--activesupport/test/core_ext/duplicable_test.rb2
-rw-r--r--activesupport/test/typed_array_test.rb51
7 files changed, 24 insertions, 96 deletions
diff --git a/activesupport/lib/active_support.rb b/activesupport/lib/active_support.rb
index 51067e910e..1df911a3f2 100644
--- a/activesupport/lib/active_support.rb
+++ b/activesupport/lib/active_support.rb
@@ -39,7 +39,6 @@ require 'active_support/cache'
require 'active_support/dependencies'
require 'active_support/deprecation'
-require 'active_support/typed_array'
require 'active_support/ordered_hash'
require 'active_support/ordered_options'
require 'active_support/option_merger'
diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb
index 9c59b7ac76..7b905930bb 100644
--- a/activesupport/lib/active_support/callbacks.rb
+++ b/activesupport/lib/active_support/callbacks.rb
@@ -96,15 +96,12 @@ module ActiveSupport
end
end
- def |(chain)
- if chain.is_a?(CallbackChain)
- chain.each { |callback| self | callback }
+ # TODO: Decompose into more Array like behavior
+ def replace_or_append!(chain)
+ if index = index(chain)
+ self[index] = chain
else
- if (found_callback = find(chain)) && (index = index(chain))
- self[index] = chain
- else
- self << chain
- end
+ self << chain
end
self
end
@@ -157,6 +154,14 @@ module ActiveSupport
self.class.new(@kind, @method, @options.dup)
end
+ def hash
+ if @identifier
+ @identifier.hash
+ else
+ @method.hash
+ end
+ end
+
def call(*args, &block)
evaluate_method(method, *args, &block) if should_run_callback?(*args)
rescue LocalJumpError
diff --git a/activesupport/lib/active_support/core_ext/duplicable.rb b/activesupport/lib/active_support/core_ext/duplicable.rb
index adbbfd8c60..8f49ddfd9e 100644
--- a/activesupport/lib/active_support/core_ext/duplicable.rb
+++ b/activesupport/lib/active_support/core_ext/duplicable.rb
@@ -35,3 +35,9 @@ class Numeric #:nodoc:
false
end
end
+
+class Class #:nodoc:
+ def duplicable?
+ false
+ end
+end
diff --git a/activesupport/lib/active_support/typed_array.rb b/activesupport/lib/active_support/typed_array.rb
deleted file mode 100644
index 1a4d8a8faf..0000000000
--- a/activesupport/lib/active_support/typed_array.rb
+++ /dev/null
@@ -1,31 +0,0 @@
-module ActiveSupport
- class TypedArray < Array
- def self.type_cast(obj)
- obj
- end
-
- def initialize(*args)
- super(*args).map! { |obj| self.class.type_cast(obj) }
- end
-
- def <<(obj)
- super(self.class.type_cast(obj))
- end
-
- def concat(array)
- super(array.map! { |obj| self.class.type_cast(obj) })
- end
-
- def insert(index, obj)
- super(index, self.class.type_cast(obj))
- end
-
- def push(*objs)
- super(*objs.map { |obj| self.class.type_cast(obj) })
- end
-
- def unshift(*objs)
- super(*objs.map { |obj| self.class.type_cast(obj) })
- end
- end
-end
diff --git a/activesupport/test/callbacks_test.rb b/activesupport/test/callbacks_test.rb
index 7f71ca2262..25b8eecef5 100644
--- a/activesupport/test/callbacks_test.rb
+++ b/activesupport/test/callbacks_test.rb
@@ -134,10 +134,10 @@ class CallbackChainTest < Test::Unit::TestCase
assert_equal :bacon, @chain.find(:bacon).method
end
- def test_union
- assert_equal [:bacon, :lettuce, :tomato], (@chain | Callback.new(:make, :bacon)).map(&:method)
- assert_equal [:bacon, :lettuce, :tomato, :turkey], (@chain | CallbackChain.build(:make, :bacon, :lettuce, :tomato, :turkey)).map(&:method)
- assert_equal [:bacon, :lettuce, :tomato, :turkey, :mayo], (@chain | Callback.new(:make, :mayo)).map(&:method)
+ def test_replace_or_append
+ assert_equal [:bacon, :lettuce, :tomato], (@chain.replace_or_append!(Callback.new(:make, :bacon))).map(&:method)
+ assert_equal [:bacon, :lettuce, :tomato, :turkey], (@chain.replace_or_append!(Callback.new(:make, :turkey))).map(&:method)
+ assert_equal [:bacon, :lettuce, :tomato, :turkey, :mayo], (@chain.replace_or_append!(Callback.new(:make, :mayo))).map(&:method)
end
def test_delete
diff --git a/activesupport/test/core_ext/duplicable_test.rb b/activesupport/test/core_ext/duplicable_test.rb
index 3ccfedccd7..8b6127f31e 100644
--- a/activesupport/test/core_ext/duplicable_test.rb
+++ b/activesupport/test/core_ext/duplicable_test.rb
@@ -1,7 +1,7 @@
require 'abstract_unit'
class DuplicableTest < Test::Unit::TestCase
- NO = [nil, false, true, :symbol, 1, 2.3, BigDecimal.new('4.56')]
+ NO = [nil, false, true, :symbol, 1, 2.3, BigDecimal.new('4.56'), Class.new]
YES = ['1', Object.new, /foo/, [], {}, Time.now]
def test_duplicable
diff --git a/activesupport/test/typed_array_test.rb b/activesupport/test/typed_array_test.rb
deleted file mode 100644
index 023f3a1b84..0000000000
--- a/activesupport/test/typed_array_test.rb
+++ /dev/null
@@ -1,51 +0,0 @@
-require 'abstract_unit'
-
-class TypedArrayTest < Test::Unit::TestCase
- class StringArray < ActiveSupport::TypedArray
- def self.type_cast(obj)
- obj.to_s
- end
- end
-
- def setup
- @array = StringArray.new
- end
-
- def test_string_array_initialize
- assert_equal ["1", "2", "3"], StringArray.new([1, "2", :"3"])
- end
-
- def test_string_array_append
- @array << 1
- @array << "2"
- @array << :"3"
- assert_equal ["1", "2", "3"], @array
- end
-
- def test_string_array_concat
- @array.concat([1, "2"])
- @array.concat([:"3"])
- assert_equal ["1", "2", "3"], @array
- end
-
- def test_string_array_insert
- @array.insert(0, 1)
- @array.insert(1, "2")
- @array.insert(2, :"3")
- assert_equal ["1", "2", "3"], @array
- end
-
- def test_string_array_push
- @array.push(1)
- @array.push("2")
- @array.push(:"3")
- assert_equal ["1", "2", "3"], @array
- end
-
- def test_string_array_unshift
- @array.unshift(:"3")
- @array.unshift("2")
- @array.unshift(1)
- assert_equal ["1", "2", "3"], @array
- end
-end