Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

use deep_dup from active_support, instead mongoid's _deep_copy

  • Loading branch information...
commit 9be8cb04058c768c41d4f402ee633ff3657029de 1 parent 0a81ade
@Houdini authored
View
2  lib/mongoid/dirty.rb
@@ -220,7 +220,7 @@ def attribute_was(attr)
# @since 2.3.0
def attribute_will_change!(attr)
unless changed_attributes.has_key?(attr)
- changed_attributes[attr] = read_attribute(attr)._deep_copy
+ changed_attributes[attr] = read_attribute(attr).deep_dup
end
end
View
6 lib/mongoid/extensions/array.rb
@@ -6,15 +6,15 @@ module Array #:nodoc:
# Make a deep copy of the array.
#
# @example Make a deep copy.
- # [ 1, 2, 3 ]._deep_copy
+ # [ 1, 2, 3 ].deep_dup
#
# @return [ Array ] The deep copy.
#
# @since 2.4.0
- def _deep_copy
+ def deep_dup
[].tap do |copy|
each do |value|
- copy.push(value._deep_copy)
+ copy.push(value.deep_dup)
end
end
end
View
16 lib/mongoid/extensions/hash.rb
@@ -3,22 +3,6 @@ module Mongoid #:nodoc:
module Extensions #:nodoc:
module Hash
- # Make a deep copy of the hash.
- #
- # @example Make a deep copy.
- # { :test => "value" }._deep_copy
- #
- # @return [ Hash ] The deep copy.
- #
- # @since 2.4.0
- def _deep_copy
- {}.tap do |copy|
- each_pair do |key, value|
- copy[key] = value._deep_copy
- end
- end
- end
-
# Expand the complex criteria into a MongoDB compliant selector hash.
#
# @example Convert the criterion.
View
4 lib/mongoid/extensions/object.rb
@@ -6,12 +6,12 @@ module Object
# Make a deep copy of the object.
#
# @example Make a deep copy.
- # "testing"._deep_copy
+ # "testing".deep_dup
#
# @return [ Object ] The deep copy.
#
# @since 2.4.0
- def _deep_copy
+ def deep_dup
duplicable? ? dup : self
end
View
4 spec/mongoid/extensions/array_spec.rb
@@ -2,7 +2,7 @@
describe Mongoid::Extensions::Array do
- describe "#_deep_copy" do
+ describe "#deep_dup" do
context "when the array hash clonable objects" do
@@ -19,7 +19,7 @@
end
let(:copy) do
- array._deep_copy
+ array.deep_dup
end
it "clones the array" do
View
27 spec/mongoid/extensions/hash_spec.rb
@@ -2,33 +2,6 @@
describe Mongoid::Extensions::Hash do
- describe "#_deep_copy" do
-
- let(:value) do
- { key: "value" }
- end
-
- let(:hash) do
- { test: value }
- end
-
- let(:copy) do
- hash._deep_copy
- end
-
- it "returns an equal object" do
- copy.should eq(hash)
- end
-
- it "returns a new instance" do
- copy.should_not equal(hash)
- end
-
- it "clones nested values" do
- copy[:test].should_not equal(value)
- end
- end
-
describe "#expand_complex_criteria" do
context "when the criterion is simple" do
View
6 spec/mongoid/extensions/object_spec.rb
@@ -2,7 +2,7 @@
describe Mongoid::Extensions::Object do
- describe "#_deep_copy" do
+ describe "#deep_dup" do
context "when the object is cloneable" do
@@ -11,7 +11,7 @@
end
let(:copy) do
- string._deep_copy
+ string.deep_dup
end
it "returns an equal object" do
@@ -30,7 +30,7 @@
end
let(:copy) do
- number._deep_copy
+ number.deep_dup
end
it "returns the same object" do
Please sign in to comment.
Something went wrong with that request. Please try again.