deep_cloneable 1.5.3 → 1.5.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.travis.yml +9 -2
- data/Appraisals +6 -6
- data/Gemfile +7 -4
- data/Gemfile.lock +46 -14
- data/README.rdoc +6 -4
- data/Rakefile +0 -13
- data/VERSION +1 -1
- data/deep_cloneable.gemspec +9 -9
- data/gemfiles/3.1.gemfile +5 -4
- data/gemfiles/3.1.gemfile.lock +15 -20
- data/gemfiles/3.2.gemfile +5 -4
- data/gemfiles/3.2.gemfile.lock +13 -18
- data/gemfiles/4.0.gemfile +10 -0
- data/gemfiles/4.0.gemfile.lock +45 -0
- data/lib/deep_cloneable.rb +4 -44
- data/test/test_deep_cloneable.rb +11 -1
- data/test/test_helper.rb +8 -5
- metadata +14 -21
- data/gemfiles/3.0.gemfile +0 -9
- data/gemfiles/3.0.gemfile.lock +0 -42
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NTMzNGQ0YmMwN2YwNjUzODdkNGZjYmFjYWEwOGMzM2Y1ZjlkMzIxOQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
Y2JmYTE3ZGY4MzM1Yjg3OTczMzVmYmYxMjk2OGVlZjMzZTBlNzA5OQ==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
OGFjYjRmY2M4YzhmOWI5YTg3YzdiZjcxN2FlZmIyN2UwOTIwMTVlYTBhOTRm
|
10
|
+
MTcwZjY0YjNjZjE4YTVmNjZlNmM2NzU0OTU3Yjg4NzRkMTQ1ODFiMGZjYmJm
|
11
|
+
NTIyYWNiMDNjZGRiM2JmODQ3ODM5ZWFkYmQ5Y2RkNGZmZTUxOGE=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NmNiZWM3NDVkOTcyN2Q5NmMyMzI1OTdmOTQ1MDA0MmNmODI0NmE2MTNkYjhm
|
14
|
+
M2I2MWI1MWMxYzA4M2U2MjY4NGQzMmEwMWMzMGY1MWZkNTA0NTAyYzRjNTA0
|
15
|
+
OWRiZTE4ZjFiZTgwN2NiMzEwMzMzZDY2YWUwNTVhY2VjOGI0MTA=
|
data/.travis.yml
CHANGED
@@ -5,6 +5,13 @@ rvm:
|
|
5
5
|
- 2.0.0
|
6
6
|
|
7
7
|
gemfile:
|
8
|
-
- gemfiles/3.0.gemfile
|
9
8
|
- gemfiles/3.1.gemfile
|
10
|
-
- gemfiles/3.2.gemfile
|
9
|
+
- gemfiles/3.2.gemfile
|
10
|
+
- gemfiles/4.0.gemfile
|
11
|
+
|
12
|
+
matrix:
|
13
|
+
exclude:
|
14
|
+
- rvm: 1.8.7
|
15
|
+
gemfile: gemfiles/4.0.gemfile
|
16
|
+
- rvm: 1.9.2
|
17
|
+
gemfile: gemfiles/4.0.gemfile
|
data/Appraisals
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
appraise '3.0' do
|
2
|
-
gem 'activerecord', '~> 3.0'
|
3
|
-
end
|
4
|
-
|
5
1
|
appraise '3.1' do
|
6
|
-
gem 'activerecord', '~> 3.1'
|
2
|
+
gem 'activerecord', '~> 3.1.0'
|
7
3
|
end
|
8
4
|
|
9
5
|
appraise '3.2' do
|
10
|
-
gem 'activerecord', '~> 3.2'
|
6
|
+
gem 'activerecord', '~> 3.2.0'
|
7
|
+
end
|
8
|
+
|
9
|
+
appraise '4.0' do
|
10
|
+
gem 'activerecord', '~> 4.0.0'
|
11
11
|
end
|
data/Gemfile
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
source 'http://rubygems.org'
|
2
2
|
|
3
|
-
gem 'activerecord', '
|
3
|
+
gem 'activerecord', '~> 3.1.0'
|
4
|
+
|
5
|
+
gem 'activesupport', '>= 3.1.0', :group => :test
|
6
|
+
gem 'appraisal', :group => :test
|
7
|
+
gem 'sqlite3', :group => :test
|
8
|
+
gem 'rdoc', '>= 2.4.2', :group => :test
|
9
|
+
#gem 'debugger', :group => :test
|
4
10
|
|
5
11
|
group :test do
|
6
|
-
gem 'appraisal'
|
7
12
|
gem 'jeweler'
|
8
|
-
gem 'sqlite3'
|
9
|
-
# gem 'debugger'
|
10
13
|
end
|
data/Gemfile.lock
CHANGED
@@ -1,32 +1,62 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
-
activemodel (3.
|
5
|
-
activesupport (= 3.
|
4
|
+
activemodel (3.1.12)
|
5
|
+
activesupport (= 3.1.12)
|
6
6
|
builder (~> 3.0.0)
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
i18n (~> 0.6)
|
8
|
+
activerecord (3.1.12)
|
9
|
+
activemodel (= 3.1.12)
|
10
|
+
activesupport (= 3.1.12)
|
11
|
+
arel (~> 2.2.3)
|
11
12
|
tzinfo (~> 0.3.29)
|
12
|
-
activesupport (3.
|
13
|
-
i18n (= 0.6.1)
|
13
|
+
activesupport (3.1.12)
|
14
14
|
multi_json (~> 1.0)
|
15
|
+
addressable (2.3.5)
|
15
16
|
appraisal (0.5.2)
|
16
17
|
bundler
|
17
18
|
rake
|
18
|
-
arel (
|
19
|
+
arel (2.2.3)
|
19
20
|
builder (3.0.4)
|
21
|
+
faraday (0.8.8)
|
22
|
+
multipart-post (~> 1.2.0)
|
20
23
|
git (1.2.5)
|
21
|
-
|
22
|
-
|
24
|
+
github_api (0.10.1)
|
25
|
+
addressable
|
26
|
+
faraday (~> 0.8.1)
|
27
|
+
hashie (>= 1.2)
|
28
|
+
multi_json (~> 1.4)
|
29
|
+
nokogiri (~> 1.5.2)
|
30
|
+
oauth2
|
31
|
+
hashie (2.0.5)
|
32
|
+
highline (1.6.19)
|
33
|
+
httpauth (0.2.0)
|
34
|
+
i18n (0.6.4)
|
35
|
+
jeweler (1.8.6)
|
36
|
+
builder
|
23
37
|
bundler (~> 1.0)
|
24
38
|
git (>= 1.2.5)
|
39
|
+
github_api (= 0.10.1)
|
40
|
+
highline (>= 1.6.15)
|
41
|
+
nokogiri (= 1.5.10)
|
25
42
|
rake
|
26
43
|
rdoc
|
27
44
|
json (1.8.0)
|
28
|
-
|
29
|
-
|
45
|
+
jwt (0.1.8)
|
46
|
+
multi_json (>= 1.5)
|
47
|
+
multi_json (1.7.9)
|
48
|
+
multi_xml (0.5.5)
|
49
|
+
multipart-post (1.2.0)
|
50
|
+
nokogiri (1.5.10)
|
51
|
+
oauth2 (0.9.2)
|
52
|
+
faraday (~> 0.8)
|
53
|
+
httpauth (~> 0.2)
|
54
|
+
jwt (~> 0.1.4)
|
55
|
+
multi_json (~> 1.0)
|
56
|
+
multi_xml (~> 0.5)
|
57
|
+
rack (~> 1.2)
|
58
|
+
rack (1.5.2)
|
59
|
+
rake (10.1.0)
|
30
60
|
rdoc (4.0.1)
|
31
61
|
json (~> 1.4)
|
32
62
|
sqlite3 (1.3.7)
|
@@ -36,7 +66,9 @@ PLATFORMS
|
|
36
66
|
ruby
|
37
67
|
|
38
68
|
DEPENDENCIES
|
39
|
-
activerecord (
|
69
|
+
activerecord (~> 3.1.0)
|
70
|
+
activesupport (>= 3.1.0)
|
40
71
|
appraisal
|
41
72
|
jeweler
|
73
|
+
rdoc (>= 2.4.2)
|
42
74
|
sqlite3
|
data/README.rdoc
CHANGED
@@ -8,7 +8,7 @@ This gem gives every ActiveRecord::Base object the possibility to do a deep clon
|
|
8
8
|
|
9
9
|
* Ruby 1.8.7, 1.9.3, 2.0.0
|
10
10
|
|
11
|
-
* Activerecord 3.
|
11
|
+
* Activerecord 3.1, 3.2, 4.0
|
12
12
|
|
13
13
|
* Rails 2.x/3.0 users, please check out the 'rails2.x-3.0' branch.
|
14
14
|
|
@@ -16,7 +16,7 @@ This gem gives every ActiveRecord::Base object the possibility to do a deep clon
|
|
16
16
|
|
17
17
|
* In your Gemfile:
|
18
18
|
|
19
|
-
gem 'deep_cloneable', '~> 1.5.
|
19
|
+
gem 'deep_cloneable', '~> 1.5.4'
|
20
20
|
|
21
21
|
== Example
|
22
22
|
|
@@ -37,13 +37,15 @@ This gem gives every ActiveRecord::Base object the possibility to do a deep clon
|
|
37
37
|
A dictionary ensures that models are not cloned multiple times when it is associated to nested models.
|
38
38
|
When using a dictionary, ensure recurring associations are cloned first:
|
39
39
|
|
40
|
-
pirate.dup :include => [:mateys, {:treasures => [:matey, :gold_pieces], :use_dictionary => true
|
40
|
+
pirate.dup :include => [:mateys, {:treasures => [:matey, :gold_pieces]}], :use_dictionary => true
|
41
41
|
|
42
42
|
If this is not an option for you, it is also possible to populate the dictionary manually in advance:
|
43
43
|
|
44
44
|
dict = { :mateys => {} }
|
45
45
|
pirate.mateys.each{|m| dict[:mateys][m] = m.dup }
|
46
|
-
pirate.dup :include => [:mateys, {:treasures => [:matey, :gold_pieces], :dictionary => dict
|
46
|
+
pirate.dup :include => [:mateys, {:treasures => [:matey, :gold_pieces]}], :dictionary => dict
|
47
|
+
|
48
|
+
When an object isn't found in the dictionary, it will be populated. By passing in an empty dictionary you can populate it automatically and reuse it in subsequent dups to avoid creating multiples of the same object where you have overlapping associations.
|
47
49
|
|
48
50
|
=== Cloning a model without an attribute
|
49
51
|
pirate.dup :except => :name
|
data/Rakefile
CHANGED
@@ -25,19 +25,6 @@ Rake::TestTask.new(:test) do |test|
|
|
25
25
|
test.verbose = true
|
26
26
|
end
|
27
27
|
|
28
|
-
begin
|
29
|
-
require 'rcov/rcovtask'
|
30
|
-
Rcov::RcovTask.new do |test|
|
31
|
-
test.libs << 'test'
|
32
|
-
test.pattern = 'test/**/test_*.rb'
|
33
|
-
test.verbose = true
|
34
|
-
end
|
35
|
-
rescue LoadError
|
36
|
-
task :rcov do
|
37
|
-
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
28
|
task :default => :test
|
42
29
|
|
43
30
|
require 'rdoc/task'
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.5.
|
1
|
+
1.5.4
|
data/deep_cloneable.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "deep_cloneable"
|
8
|
-
s.version = "1.5.
|
8
|
+
s.version = "1.5.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Reinier de Lange"]
|
12
|
-
s.date = "2013-
|
12
|
+
s.date = "2013-08-12"
|
13
13
|
s.description = "Extends the functionality of ActiveRecord::Base#clone to perform a deep clone that includes user specified associations. "
|
14
14
|
s.email = "r.j.delange@nedforce.nl"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -27,12 +27,12 @@ Gem::Specification.new do |s|
|
|
27
27
|
"Rakefile",
|
28
28
|
"VERSION",
|
29
29
|
"deep_cloneable.gemspec",
|
30
|
-
"gemfiles/3.0.gemfile",
|
31
|
-
"gemfiles/3.0.gemfile.lock",
|
32
30
|
"gemfiles/3.1.gemfile",
|
33
31
|
"gemfiles/3.1.gemfile.lock",
|
34
32
|
"gemfiles/3.2.gemfile",
|
35
33
|
"gemfiles/3.2.gemfile.lock",
|
34
|
+
"gemfiles/4.0.gemfile",
|
35
|
+
"gemfiles/4.0.gemfile.lock",
|
36
36
|
"init.rb",
|
37
37
|
"lib/deep_cloneable.rb",
|
38
38
|
"test/database.yml",
|
@@ -43,19 +43,19 @@ Gem::Specification.new do |s|
|
|
43
43
|
]
|
44
44
|
s.homepage = "http://github.com/moiristo/deep_cloneable"
|
45
45
|
s.require_paths = ["lib"]
|
46
|
-
s.rubygems_version = "
|
46
|
+
s.rubygems_version = "2.0.6"
|
47
47
|
s.summary = "This gem gives every ActiveRecord::Base object the possibility to do a deep clone."
|
48
48
|
|
49
49
|
if s.respond_to? :specification_version then
|
50
|
-
s.specification_version =
|
50
|
+
s.specification_version = 4
|
51
51
|
|
52
52
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
53
|
-
s.add_runtime_dependency(%q<activerecord>, ["
|
53
|
+
s.add_runtime_dependency(%q<activerecord>, ["~> 3.1.0"])
|
54
54
|
else
|
55
|
-
s.add_dependency(%q<activerecord>, ["
|
55
|
+
s.add_dependency(%q<activerecord>, ["~> 3.1.0"])
|
56
56
|
end
|
57
57
|
else
|
58
|
-
s.add_dependency(%q<activerecord>, ["
|
58
|
+
s.add_dependency(%q<activerecord>, ["~> 3.1.0"])
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
data/gemfiles/3.1.gemfile
CHANGED
@@ -2,8 +2,9 @@
|
|
2
2
|
|
3
3
|
source "http://rubygems.org"
|
4
4
|
|
5
|
-
gem "
|
6
|
-
gem "
|
7
|
-
gem "sqlite3"
|
8
|
-
gem "
|
5
|
+
gem "activesupport", ">= 3.1.0", :group=>:test
|
6
|
+
gem "appraisal", :group=>:test
|
7
|
+
gem "sqlite3", :group=>:test
|
8
|
+
gem "rdoc", ">= 2.4.2", :group=>:test
|
9
|
+
gem "activerecord", "~> 3.1.0"
|
9
10
|
|
data/gemfiles/3.1.gemfile.lock
CHANGED
@@ -1,32 +1,26 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
-
activemodel (3.
|
5
|
-
activesupport (= 3.
|
4
|
+
activemodel (3.1.12)
|
5
|
+
activesupport (= 3.1.12)
|
6
6
|
builder (~> 3.0.0)
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
i18n (~> 0.6)
|
8
|
+
activerecord (3.1.12)
|
9
|
+
activemodel (= 3.1.12)
|
10
|
+
activesupport (= 3.1.12)
|
11
|
+
arel (~> 2.2.3)
|
11
12
|
tzinfo (~> 0.3.29)
|
12
|
-
activesupport (3.
|
13
|
-
i18n (= 0.6.1)
|
13
|
+
activesupport (3.1.12)
|
14
14
|
multi_json (~> 1.0)
|
15
15
|
appraisal (0.5.2)
|
16
16
|
bundler
|
17
17
|
rake
|
18
|
-
arel (
|
18
|
+
arel (2.2.3)
|
19
19
|
builder (3.0.4)
|
20
|
-
|
21
|
-
i18n (0.6.1)
|
22
|
-
jeweler (1.8.4)
|
23
|
-
bundler (~> 1.0)
|
24
|
-
git (>= 1.2.5)
|
25
|
-
rake
|
26
|
-
rdoc
|
20
|
+
i18n (0.6.4)
|
27
21
|
json (1.8.0)
|
28
|
-
multi_json (1.7.
|
29
|
-
rake (10.0
|
22
|
+
multi_json (1.7.9)
|
23
|
+
rake (10.1.0)
|
30
24
|
rdoc (4.0.1)
|
31
25
|
json (~> 1.4)
|
32
26
|
sqlite3 (1.3.7)
|
@@ -36,7 +30,8 @@ PLATFORMS
|
|
36
30
|
ruby
|
37
31
|
|
38
32
|
DEPENDENCIES
|
39
|
-
activerecord (~> 3.1)
|
33
|
+
activerecord (~> 3.1.0)
|
34
|
+
activesupport (>= 3.1.0)
|
40
35
|
appraisal
|
41
|
-
|
36
|
+
rdoc (>= 2.4.2)
|
42
37
|
sqlite3
|
data/gemfiles/3.2.gemfile
CHANGED
@@ -2,8 +2,9 @@
|
|
2
2
|
|
3
3
|
source "http://rubygems.org"
|
4
4
|
|
5
|
-
gem "
|
6
|
-
gem "
|
7
|
-
gem "sqlite3"
|
8
|
-
gem "
|
5
|
+
gem "activesupport", ">= 3.1.0", :group=>:test
|
6
|
+
gem "appraisal", :group=>:test
|
7
|
+
gem "sqlite3", :group=>:test
|
8
|
+
gem "rdoc", ">= 2.4.2", :group=>:test
|
9
|
+
gem "activerecord", "~> 3.2.0"
|
9
10
|
|
data/gemfiles/3.2.gemfile.lock
CHANGED
@@ -1,32 +1,26 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
-
activemodel (3.2.
|
5
|
-
activesupport (= 3.2.
|
4
|
+
activemodel (3.2.14)
|
5
|
+
activesupport (= 3.2.14)
|
6
6
|
builder (~> 3.0.0)
|
7
|
-
activerecord (3.2.
|
8
|
-
activemodel (= 3.2.
|
9
|
-
activesupport (= 3.2.
|
7
|
+
activerecord (3.2.14)
|
8
|
+
activemodel (= 3.2.14)
|
9
|
+
activesupport (= 3.2.14)
|
10
10
|
arel (~> 3.0.2)
|
11
11
|
tzinfo (~> 0.3.29)
|
12
|
-
activesupport (3.2.
|
13
|
-
i18n (
|
12
|
+
activesupport (3.2.14)
|
13
|
+
i18n (~> 0.6, >= 0.6.4)
|
14
14
|
multi_json (~> 1.0)
|
15
15
|
appraisal (0.5.2)
|
16
16
|
bundler
|
17
17
|
rake
|
18
18
|
arel (3.0.2)
|
19
19
|
builder (3.0.4)
|
20
|
-
|
21
|
-
i18n (0.6.1)
|
22
|
-
jeweler (1.8.4)
|
23
|
-
bundler (~> 1.0)
|
24
|
-
git (>= 1.2.5)
|
25
|
-
rake
|
26
|
-
rdoc
|
20
|
+
i18n (0.6.4)
|
27
21
|
json (1.8.0)
|
28
|
-
multi_json (1.7.
|
29
|
-
rake (10.0
|
22
|
+
multi_json (1.7.9)
|
23
|
+
rake (10.1.0)
|
30
24
|
rdoc (4.0.1)
|
31
25
|
json (~> 1.4)
|
32
26
|
sqlite3 (1.3.7)
|
@@ -36,7 +30,8 @@ PLATFORMS
|
|
36
30
|
ruby
|
37
31
|
|
38
32
|
DEPENDENCIES
|
39
|
-
activerecord (~> 3.2)
|
33
|
+
activerecord (~> 3.2.0)
|
34
|
+
activesupport (>= 3.1.0)
|
40
35
|
appraisal
|
41
|
-
|
36
|
+
rdoc (>= 2.4.2)
|
42
37
|
sqlite3
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "http://rubygems.org"
|
4
|
+
|
5
|
+
gem "activesupport", ">= 3.1.0", :group=>:test
|
6
|
+
gem "appraisal", :group=>:test
|
7
|
+
gem "sqlite3", :group=>:test
|
8
|
+
gem "rdoc", ">= 2.4.2", :group=>:test
|
9
|
+
gem "activerecord", "~> 4.0.0"
|
10
|
+
|
@@ -0,0 +1,45 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activemodel (4.0.0)
|
5
|
+
activesupport (= 4.0.0)
|
6
|
+
builder (~> 3.1.0)
|
7
|
+
activerecord (4.0.0)
|
8
|
+
activemodel (= 4.0.0)
|
9
|
+
activerecord-deprecated_finders (~> 1.0.2)
|
10
|
+
activesupport (= 4.0.0)
|
11
|
+
arel (~> 4.0.0)
|
12
|
+
activerecord-deprecated_finders (1.0.3)
|
13
|
+
activesupport (4.0.0)
|
14
|
+
i18n (~> 0.6, >= 0.6.4)
|
15
|
+
minitest (~> 4.2)
|
16
|
+
multi_json (~> 1.3)
|
17
|
+
thread_safe (~> 0.1)
|
18
|
+
tzinfo (~> 0.3.37)
|
19
|
+
appraisal (0.5.2)
|
20
|
+
bundler
|
21
|
+
rake
|
22
|
+
arel (4.0.0)
|
23
|
+
atomic (1.1.12)
|
24
|
+
builder (3.1.4)
|
25
|
+
i18n (0.6.4)
|
26
|
+
json (1.8.0)
|
27
|
+
minitest (4.7.5)
|
28
|
+
multi_json (1.7.9)
|
29
|
+
rake (10.1.0)
|
30
|
+
rdoc (4.0.1)
|
31
|
+
json (~> 1.4)
|
32
|
+
sqlite3 (1.3.7)
|
33
|
+
thread_safe (0.1.2)
|
34
|
+
atomic
|
35
|
+
tzinfo (0.3.37)
|
36
|
+
|
37
|
+
PLATFORMS
|
38
|
+
ruby
|
39
|
+
|
40
|
+
DEPENDENCIES
|
41
|
+
activerecord (~> 4.0.0)
|
42
|
+
activesupport (>= 3.1.0)
|
43
|
+
appraisal
|
44
|
+
rdoc (>= 2.4.2)
|
45
|
+
sqlite3
|
data/lib/deep_cloneable.rb
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
class ActiveRecord::Base
|
2
2
|
module DeepCloneable
|
3
|
-
|
4
|
-
|
5
|
-
# module and call the original with super().
|
6
|
-
unless Object.respond_to?(:initialize_dup, true)
|
3
|
+
|
4
|
+
if ActiveRecord::VERSION::MAJOR < 4
|
7
5
|
ActiveRecord::Base.class_eval do
|
6
|
+
protected :initialize_dup
|
8
7
|
module Dup
|
9
8
|
def dup
|
10
9
|
copy = super
|
@@ -17,46 +16,7 @@ class ActiveRecord::Base
|
|
17
16
|
end
|
18
17
|
end
|
19
18
|
|
20
|
-
#
|
21
|
-
# if passed the :include option, it will deep clone the given associations
|
22
|
-
# if passed the :except option, it won't clone the given attributes
|
23
|
-
#
|
24
|
-
# === Usage:
|
25
|
-
#
|
26
|
-
# ==== Cloning one single association
|
27
|
-
# pirate.clone :include => :mateys
|
28
|
-
#
|
29
|
-
# ==== Cloning multiple associations
|
30
|
-
# pirate.clone :include => [:mateys, :treasures]
|
31
|
-
#
|
32
|
-
# ==== Cloning really deep
|
33
|
-
# pirate.clone :include => {:treasures => :gold_pieces}
|
34
|
-
#
|
35
|
-
# ==== Cloning really deep with multiple associations
|
36
|
-
# pirate.clone :include => [:mateys, {:treasures => :gold_pieces}]
|
37
|
-
#
|
38
|
-
# ==== Cloning really deep with multiple associations and a dictionary
|
39
|
-
#
|
40
|
-
# A dictionary ensures that models are not cloned multiple times when it is associated to nested models.
|
41
|
-
# When using a dictionary, ensure recurring associations are cloned first:
|
42
|
-
#
|
43
|
-
# pirate.clone :include => [:mateys, {:treasures => [:matey, :gold_pieces], :use_dictionary => true }]
|
44
|
-
#
|
45
|
-
# If this is not an option for you, it is also possible to populate the dictionary manually in advance:
|
46
|
-
#
|
47
|
-
# dict = { :mateys => {} }
|
48
|
-
# pirate.mateys.each{|m| dict[:mateys][m] = m.clone }
|
49
|
-
# pirate.clone :include => [:mateys, {:treasures => [:matey, :gold_pieces], :dictionary => dict }]
|
50
|
-
#
|
51
|
-
# ==== Cloning a model without an attribute
|
52
|
-
# pirate.clone :except => :name
|
53
|
-
#
|
54
|
-
# ==== Cloning a model without multiple attributes
|
55
|
-
# pirate.clone :except => [:name, :nick_name]
|
56
|
-
#
|
57
|
-
# ==== Cloning a model without an attribute or nested multiple attributes
|
58
|
-
# pirate.clone :include => :parrot, :except => [:name, { :parrot => [:name] }]
|
59
|
-
#
|
19
|
+
# Deep dups an ActiveRecord model. See README.rdoc
|
60
20
|
def dup *args, &block
|
61
21
|
options = args[0] || {}
|
62
22
|
|
data/test/test_deep_cloneable.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/test_helper'
|
2
2
|
|
3
3
|
class TestDeepCloneable < Test::Unit::TestCase
|
4
|
-
load_schema
|
5
4
|
|
6
5
|
def setup
|
7
6
|
@jack = Pirate.create(:name => 'Jack Sparrow', :nick_name => 'Captain Jack', :age => 30)
|
@@ -199,6 +198,17 @@ class TestDeepCloneable < Test::Unit::TestCase
|
|
199
198
|
assert_equal @person1.cars, dup_person.cars
|
200
199
|
assert_equal 2, dup_person.cars.count
|
201
200
|
end
|
201
|
+
|
202
|
+
def test_should_dup_joined_association
|
203
|
+
subject1 = Subject.create(:name => 'subject 1')
|
204
|
+
subject2 = Subject.create(:name => 'subject 2')
|
205
|
+
student = Student.create(:name => 'Parent', :subjects => [subject1, subject2])
|
206
|
+
|
207
|
+
dup = student.dup :include => { :student_assignments => :subject }
|
208
|
+
dup.save # Subjects will have been set after save
|
209
|
+
assert_equal 2, dup.subjects.size
|
210
|
+
[subject1, subject2].each{|subject| assert !dup.subjects.include?(subject) }
|
211
|
+
end
|
202
212
|
|
203
213
|
def test_parent_validations_run_on_save_after_clone
|
204
214
|
child = ChildWithValidation.create :name => 'Jimmy'
|
data/test/test_helper.rb
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'test/unit'
|
3
|
-
require 'pp'
|
4
|
-
#
|
3
|
+
#require 'pp'
|
4
|
+
#require 'debugger'
|
5
5
|
|
6
6
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
7
7
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
8
8
|
|
9
9
|
require 'active_record'
|
10
|
-
require
|
11
|
-
require 'models'
|
10
|
+
require 'active_support/buffered_logger'
|
12
11
|
|
13
12
|
def load_schema
|
14
13
|
config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
|
@@ -32,4 +31,8 @@ def load_schema
|
|
32
31
|
end
|
33
32
|
ActiveRecord::Base.establish_connection(config[db_adapter])
|
34
33
|
load(File.dirname(__FILE__) + "/schema.rb")
|
35
|
-
end
|
34
|
+
end
|
35
|
+
|
36
|
+
load_schema
|
37
|
+
require File.dirname(__FILE__) + '/../init.rb'
|
38
|
+
require 'models'
|
metadata
CHANGED
@@ -1,32 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deep_cloneable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
5
|
-
prerelease:
|
4
|
+
version: 1.5.4
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Reinier de Lange
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-08-12 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
|
-
name: activerecord
|
16
14
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
15
|
requirements:
|
19
|
-
- -
|
16
|
+
- - ~>
|
20
17
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
22
|
-
type: :runtime
|
23
|
-
prerelease: false
|
18
|
+
version: 3.1.0
|
24
19
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
20
|
requirements:
|
27
|
-
- -
|
21
|
+
- - ~>
|
28
22
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
23
|
+
version: 3.1.0
|
24
|
+
type: :runtime
|
25
|
+
prerelease: false
|
26
|
+
name: activerecord
|
30
27
|
description: ! 'Extends the functionality of ActiveRecord::Base#clone to perform a
|
31
28
|
deep clone that includes user specified associations. '
|
32
29
|
email: r.j.delange@nedforce.nl
|
@@ -46,12 +43,12 @@ files:
|
|
46
43
|
- Rakefile
|
47
44
|
- VERSION
|
48
45
|
- deep_cloneable.gemspec
|
49
|
-
- gemfiles/3.0.gemfile
|
50
|
-
- gemfiles/3.0.gemfile.lock
|
51
46
|
- gemfiles/3.1.gemfile
|
52
47
|
- gemfiles/3.1.gemfile.lock
|
53
48
|
- gemfiles/3.2.gemfile
|
54
49
|
- gemfiles/3.2.gemfile.lock
|
50
|
+
- gemfiles/4.0.gemfile
|
51
|
+
- gemfiles/4.0.gemfile.lock
|
55
52
|
- init.rb
|
56
53
|
- lib/deep_cloneable.rb
|
57
54
|
- test/database.yml
|
@@ -61,30 +58,26 @@ files:
|
|
61
58
|
- test/test_helper.rb
|
62
59
|
homepage: http://github.com/moiristo/deep_cloneable
|
63
60
|
licenses: []
|
61
|
+
metadata: {}
|
64
62
|
post_install_message:
|
65
63
|
rdoc_options: []
|
66
64
|
require_paths:
|
67
65
|
- lib
|
68
66
|
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
-
none: false
|
70
67
|
requirements:
|
71
68
|
- - ! '>='
|
72
69
|
- !ruby/object:Gem::Version
|
73
70
|
version: '0'
|
74
|
-
segments:
|
75
|
-
- 0
|
76
|
-
hash: 836964881985067295
|
77
71
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
-
none: false
|
79
72
|
requirements:
|
80
73
|
- - ! '>='
|
81
74
|
- !ruby/object:Gem::Version
|
82
75
|
version: '0'
|
83
76
|
requirements: []
|
84
77
|
rubyforge_project:
|
85
|
-
rubygems_version:
|
78
|
+
rubygems_version: 2.0.6
|
86
79
|
signing_key:
|
87
|
-
specification_version:
|
80
|
+
specification_version: 4
|
88
81
|
summary: This gem gives every ActiveRecord::Base object the possibility to do a deep
|
89
82
|
clone.
|
90
83
|
test_files: []
|
data/gemfiles/3.0.gemfile
DELETED
data/gemfiles/3.0.gemfile.lock
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
GEM
|
2
|
-
remote: http://rubygems.org/
|
3
|
-
specs:
|
4
|
-
activemodel (3.2.13)
|
5
|
-
activesupport (= 3.2.13)
|
6
|
-
builder (~> 3.0.0)
|
7
|
-
activerecord (3.2.13)
|
8
|
-
activemodel (= 3.2.13)
|
9
|
-
activesupport (= 3.2.13)
|
10
|
-
arel (~> 3.0.2)
|
11
|
-
tzinfo (~> 0.3.29)
|
12
|
-
activesupport (3.2.13)
|
13
|
-
i18n (= 0.6.1)
|
14
|
-
multi_json (~> 1.0)
|
15
|
-
appraisal (0.5.2)
|
16
|
-
bundler
|
17
|
-
rake
|
18
|
-
arel (3.0.2)
|
19
|
-
builder (3.0.4)
|
20
|
-
git (1.2.5)
|
21
|
-
i18n (0.6.1)
|
22
|
-
jeweler (1.8.4)
|
23
|
-
bundler (~> 1.0)
|
24
|
-
git (>= 1.2.5)
|
25
|
-
rake
|
26
|
-
rdoc
|
27
|
-
json (1.8.0)
|
28
|
-
multi_json (1.7.3)
|
29
|
-
rake (10.0.4)
|
30
|
-
rdoc (4.0.1)
|
31
|
-
json (~> 1.4)
|
32
|
-
sqlite3 (1.3.7)
|
33
|
-
tzinfo (0.3.37)
|
34
|
-
|
35
|
-
PLATFORMS
|
36
|
-
ruby
|
37
|
-
|
38
|
-
DEPENDENCIES
|
39
|
-
activerecord (~> 3.0)
|
40
|
-
appraisal
|
41
|
-
jeweler
|
42
|
-
sqlite3
|