deep_cloneable 2.0.2 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Appraisals +2 -1
- data/Gemfile +1 -0
- data/Gemfile.lock +26 -24
- data/LICENSE +1 -1
- data/README.rdoc +6 -3
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/deep_cloneable.gemspec +8 -4
- data/gemfiles/3.1.gemfile +1 -0
- data/gemfiles/3.1.gemfile.lock +9 -8
- data/gemfiles/3.2.gemfile +1 -0
- data/gemfiles/3.2.gemfile.lock +9 -8
- data/gemfiles/4.0.gemfile +1 -0
- data/gemfiles/4.0.gemfile.lock +8 -7
- data/gemfiles/4.1.gemfile +1 -0
- data/gemfiles/4.1.gemfile.lock +14 -13
- data/gemfiles/4.2.gemfile +2 -1
- data/gemfiles/4.2.gemfile.lock +18 -17
- data/lib/deep_cloneable.rb +47 -16
- data/test/models.rb +15 -0
- data/test/schema.rb +19 -0
- data/test/test_deep_cloneable.rb +47 -1
- data/test/test_helper.rb +2 -0
- metadata +19 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 31259626578b39e7deaa9ae9af33f0cc5da9bfbe
|
4
|
+
data.tar.gz: 959e624306e8e560775e6e851e1c54eee032d2f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db538e17fe17aa1c3b1668dba797211b88b8535d73d7aef46276c706d59acd915d82943453bfab26423e71b89d9f01ccc8a8659f4844751becd895757da63cde
|
7
|
+
data.tar.gz: 6599bdef23fe3a4780e621b88cc18dea62e2dc7bce0188cb7c10ae24a17d9fe730bf64ef22f824b377a2ecfb0dc01fe3eac9c24be29a135e8e73bdf2fea8ef20
|
data/Appraisals
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,29 +1,31 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
-
activemodel (4.
|
5
|
-
activesupport (= 4.
|
6
|
-
builder (~> 3.1)
|
7
|
-
activerecord (4.
|
8
|
-
activemodel (= 4.
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
4
|
+
activemodel (4.0.3)
|
5
|
+
activesupport (= 4.0.3)
|
6
|
+
builder (~> 3.1.0)
|
7
|
+
activerecord (4.0.3)
|
8
|
+
activemodel (= 4.0.3)
|
9
|
+
activerecord-deprecated_finders (~> 1.0.2)
|
10
|
+
activesupport (= 4.0.3)
|
11
|
+
arel (~> 4.0.0)
|
12
|
+
activerecord-deprecated_finders (1.0.3)
|
13
|
+
activesupport (4.0.3)
|
14
|
+
i18n (~> 0.6, >= 0.6.4)
|
15
|
+
minitest (~> 4.2)
|
16
|
+
multi_json (~> 1.3)
|
15
17
|
thread_safe (~> 0.1)
|
16
|
-
tzinfo (~>
|
17
|
-
addressable (2.3.
|
18
|
+
tzinfo (~> 0.3.37)
|
19
|
+
addressable (2.3.7)
|
18
20
|
appraisal (1.0.2)
|
19
21
|
bundler
|
20
22
|
rake
|
21
23
|
thor (>= 0.14.0)
|
22
|
-
arel (
|
23
|
-
builder (3.
|
24
|
+
arel (4.0.2)
|
25
|
+
builder (3.1.4)
|
24
26
|
faraday (0.8.9)
|
25
27
|
multipart-post (~> 1.2.0)
|
26
|
-
git (1.2.
|
28
|
+
git (1.2.9.1)
|
27
29
|
github_api (0.10.1)
|
28
30
|
addressable
|
29
31
|
faraday (~> 0.8.1)
|
@@ -31,9 +33,9 @@ GEM
|
|
31
33
|
multi_json (~> 1.4)
|
32
34
|
nokogiri (~> 1.5.2)
|
33
35
|
oauth2
|
34
|
-
hashie (3.
|
36
|
+
hashie (3.4.0)
|
35
37
|
highline (1.6.21)
|
36
|
-
i18n (0.
|
38
|
+
i18n (0.6.5)
|
37
39
|
jeweler (2.0.1)
|
38
40
|
builder
|
39
41
|
bundler (>= 1.0)
|
@@ -43,9 +45,9 @@ GEM
|
|
43
45
|
nokogiri (>= 1.5.10)
|
44
46
|
rake
|
45
47
|
rdoc
|
46
|
-
json (1.8.
|
47
|
-
jwt (1.2.
|
48
|
-
minitest (
|
48
|
+
json (1.8.2)
|
49
|
+
jwt (1.2.1)
|
50
|
+
minitest (4.7.5)
|
49
51
|
multi_json (1.10.1)
|
50
52
|
multi_xml (0.5.5)
|
51
53
|
multipart-post (1.2.0)
|
@@ -56,15 +58,14 @@ GEM
|
|
56
58
|
multi_json (~> 1.3)
|
57
59
|
multi_xml (~> 0.5)
|
58
60
|
rack (~> 1.2)
|
59
|
-
rack (1.
|
61
|
+
rack (1.6.0)
|
60
62
|
rake (10.4.2)
|
61
63
|
rdoc (4.2.0)
|
62
64
|
json (~> 1.4)
|
63
65
|
sqlite3 (1.3.10)
|
64
66
|
thor (0.19.1)
|
65
67
|
thread_safe (0.3.4)
|
66
|
-
tzinfo (
|
67
|
-
thread_safe (~> 0.1)
|
68
|
+
tzinfo (0.3.43)
|
68
69
|
|
69
70
|
PLATFORMS
|
70
71
|
ruby
|
@@ -72,6 +73,7 @@ PLATFORMS
|
|
72
73
|
DEPENDENCIES
|
73
74
|
activerecord (>= 3.1.0, < 5.0.0)
|
74
75
|
appraisal
|
76
|
+
i18n (~> 0.6.5)
|
75
77
|
jeweler
|
76
78
|
minitest
|
77
79
|
nokogiri (~> 1.5.0)
|
data/LICENSE
CHANGED
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.2, 1.9.3, 2.0.0, 2.1.5 (tested)
|
10
10
|
|
11
|
-
* Activerecord 3.1, 3.2, 4.0, 4.1, 4.2
|
11
|
+
* Activerecord 3.1, 3.2, 4.0, 4.1, 4.2
|
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', '~> 2.0
|
19
|
+
gem 'deep_cloneable', '~> 2.1.0'
|
20
20
|
|
21
21
|
== Upgrading from v1
|
22
22
|
|
@@ -80,6 +80,9 @@ so be sure to check whether the object actually responds to your method of choic
|
|
80
80
|
=== Cloning a model with explicitly assigned attributes or nested multiple attributes
|
81
81
|
pirate.deep_clone :include => :parrot, :only => [:name, { :parrot => [:name] }]
|
82
82
|
|
83
|
+
=== Conditional cloning
|
84
|
+
pirate.deep_clone(:include => [{:treasures => { :gold_pieces => { :if => lambda{|piece| piece.is_a?(Parrot) } } } }, :mateys => { :unless => lambda{|matey| matey.is_a?(GoldPiece) } } ])
|
85
|
+
|
83
86
|
== Note on Patches/Pull Requests
|
84
87
|
|
85
88
|
* Fork the project.
|
@@ -92,4 +95,4 @@ so be sure to check whether the object actually responds to your method of choic
|
|
92
95
|
|
93
96
|
== Copyright
|
94
97
|
|
95
|
-
Copyright (c)
|
98
|
+
Copyright (c) 2015 Reinier de Lange. See LICENSE for details.
|
data/Rakefile
CHANGED
@@ -11,6 +11,7 @@ begin
|
|
11
11
|
gem.email = "r.j.delange@nedforce.nl"
|
12
12
|
gem.homepage = "http://github.com/moiristo/deep_cloneable"
|
13
13
|
gem.authors = ["Reinier de Lange"]
|
14
|
+
gem.license = "MIT"
|
14
15
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
16
|
end
|
16
17
|
Jeweler::GemcutterTasks.new
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.0
|
1
|
+
2.1.0
|
data/deep_cloneable.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: deep_cloneable 2.0
|
5
|
+
# stub: deep_cloneable 2.1.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "deep_cloneable"
|
9
|
-
s.version = "2.0
|
9
|
+
s.version = "2.1.0"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Reinier de Lange"]
|
14
|
-
s.date = "
|
14
|
+
s.date = "2015-03-10"
|
15
15
|
s.description = "Extends the functionality of ActiveRecord::Base#clone to perform a deep clone that includes user specified associations. "
|
16
16
|
s.email = "r.j.delange@nedforce.nl"
|
17
17
|
s.extra_rdoc_files = [
|
@@ -48,7 +48,8 @@ Gem::Specification.new do |s|
|
|
48
48
|
"test/test_helper.rb"
|
49
49
|
]
|
50
50
|
s.homepage = "http://github.com/moiristo/deep_cloneable"
|
51
|
-
s.
|
51
|
+
s.licenses = ["MIT"]
|
52
|
+
s.rubygems_version = "2.4.3"
|
52
53
|
s.summary = "This gem gives every ActiveRecord::Base object the possibility to do a deep clone."
|
53
54
|
|
54
55
|
if s.respond_to? :specification_version then
|
@@ -56,11 +57,14 @@ Gem::Specification.new do |s|
|
|
56
57
|
|
57
58
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
58
59
|
s.add_runtime_dependency(%q<activerecord>, ["< 5.0.0", ">= 3.1.0"])
|
60
|
+
s.add_runtime_dependency(%q<i18n>, ["~> 0.6.5"])
|
59
61
|
else
|
60
62
|
s.add_dependency(%q<activerecord>, ["< 5.0.0", ">= 3.1.0"])
|
63
|
+
s.add_dependency(%q<i18n>, ["~> 0.6.5"])
|
61
64
|
end
|
62
65
|
else
|
63
66
|
s.add_dependency(%q<activerecord>, ["< 5.0.0", ">= 3.1.0"])
|
67
|
+
s.add_dependency(%q<i18n>, ["~> 0.6.5"])
|
64
68
|
end
|
65
69
|
end
|
66
70
|
|
data/gemfiles/3.1.gemfile
CHANGED
data/gemfiles/3.1.gemfile.lock
CHANGED
@@ -12,7 +12,7 @@ GEM
|
|
12
12
|
tzinfo (~> 0.3.29)
|
13
13
|
activesupport (3.1.12)
|
14
14
|
multi_json (~> 1.0)
|
15
|
-
addressable (2.3.
|
15
|
+
addressable (2.3.7)
|
16
16
|
appraisal (1.0.2)
|
17
17
|
bundler
|
18
18
|
rake
|
@@ -21,7 +21,7 @@ GEM
|
|
21
21
|
builder (3.0.4)
|
22
22
|
faraday (0.8.9)
|
23
23
|
multipart-post (~> 1.2.0)
|
24
|
-
git (1.2.
|
24
|
+
git (1.2.9.1)
|
25
25
|
github_api (0.10.1)
|
26
26
|
addressable
|
27
27
|
faraday (~> 0.8.1)
|
@@ -29,7 +29,7 @@ GEM
|
|
29
29
|
multi_json (~> 1.4)
|
30
30
|
nokogiri (~> 1.5.2)
|
31
31
|
oauth2
|
32
|
-
hashie (3.
|
32
|
+
hashie (3.4.0)
|
33
33
|
highline (1.6.21)
|
34
34
|
i18n (0.6.11)
|
35
35
|
jeweler (2.0.1)
|
@@ -41,9 +41,9 @@ GEM
|
|
41
41
|
nokogiri (>= 1.5.10)
|
42
42
|
rake
|
43
43
|
rdoc
|
44
|
-
json (1.8.
|
45
|
-
jwt (1.2.
|
46
|
-
minitest (5.5.
|
44
|
+
json (1.8.2)
|
45
|
+
jwt (1.2.1)
|
46
|
+
minitest (5.5.1)
|
47
47
|
multi_json (1.10.1)
|
48
48
|
multi_xml (0.5.5)
|
49
49
|
multipart-post (1.2.0)
|
@@ -54,13 +54,13 @@ GEM
|
|
54
54
|
multi_json (~> 1.3)
|
55
55
|
multi_xml (~> 0.5)
|
56
56
|
rack (~> 1.2)
|
57
|
-
rack (1.
|
57
|
+
rack (1.6.0)
|
58
58
|
rake (10.4.2)
|
59
59
|
rdoc (4.2.0)
|
60
60
|
json (~> 1.4)
|
61
61
|
sqlite3 (1.3.10)
|
62
62
|
thor (0.19.1)
|
63
|
-
tzinfo (0.3.
|
63
|
+
tzinfo (0.3.43)
|
64
64
|
|
65
65
|
PLATFORMS
|
66
66
|
ruby
|
@@ -68,6 +68,7 @@ PLATFORMS
|
|
68
68
|
DEPENDENCIES
|
69
69
|
activerecord (~> 3.1.0)
|
70
70
|
appraisal
|
71
|
+
i18n (~> 0.6.5)
|
71
72
|
jeweler
|
72
73
|
minitest
|
73
74
|
nokogiri (~> 1.5.0)
|
data/gemfiles/3.2.gemfile
CHANGED
data/gemfiles/3.2.gemfile.lock
CHANGED
@@ -12,7 +12,7 @@ GEM
|
|
12
12
|
activesupport (3.2.21)
|
13
13
|
i18n (~> 0.6, >= 0.6.4)
|
14
14
|
multi_json (~> 1.0)
|
15
|
-
addressable (2.3.
|
15
|
+
addressable (2.3.7)
|
16
16
|
appraisal (1.0.2)
|
17
17
|
bundler
|
18
18
|
rake
|
@@ -21,7 +21,7 @@ GEM
|
|
21
21
|
builder (3.0.4)
|
22
22
|
faraday (0.8.9)
|
23
23
|
multipart-post (~> 1.2.0)
|
24
|
-
git (1.2.
|
24
|
+
git (1.2.9.1)
|
25
25
|
github_api (0.10.1)
|
26
26
|
addressable
|
27
27
|
faraday (~> 0.8.1)
|
@@ -29,7 +29,7 @@ GEM
|
|
29
29
|
multi_json (~> 1.4)
|
30
30
|
nokogiri (~> 1.5.2)
|
31
31
|
oauth2
|
32
|
-
hashie (3.
|
32
|
+
hashie (3.4.0)
|
33
33
|
highline (1.6.21)
|
34
34
|
i18n (0.6.11)
|
35
35
|
jeweler (2.0.1)
|
@@ -41,9 +41,9 @@ GEM
|
|
41
41
|
nokogiri (>= 1.5.10)
|
42
42
|
rake
|
43
43
|
rdoc
|
44
|
-
json (1.8.
|
45
|
-
jwt (1.2.
|
46
|
-
minitest (5.5.
|
44
|
+
json (1.8.2)
|
45
|
+
jwt (1.2.1)
|
46
|
+
minitest (5.5.1)
|
47
47
|
multi_json (1.10.1)
|
48
48
|
multi_xml (0.5.5)
|
49
49
|
multipart-post (1.2.0)
|
@@ -54,13 +54,13 @@ GEM
|
|
54
54
|
multi_json (~> 1.3)
|
55
55
|
multi_xml (~> 0.5)
|
56
56
|
rack (~> 1.2)
|
57
|
-
rack (1.
|
57
|
+
rack (1.6.0)
|
58
58
|
rake (10.4.2)
|
59
59
|
rdoc (4.2.0)
|
60
60
|
json (~> 1.4)
|
61
61
|
sqlite3 (1.3.10)
|
62
62
|
thor (0.19.1)
|
63
|
-
tzinfo (0.3.
|
63
|
+
tzinfo (0.3.43)
|
64
64
|
|
65
65
|
PLATFORMS
|
66
66
|
ruby
|
@@ -68,6 +68,7 @@ PLATFORMS
|
|
68
68
|
DEPENDENCIES
|
69
69
|
activerecord (~> 3.2.0)
|
70
70
|
appraisal
|
71
|
+
i18n (~> 0.6.5)
|
71
72
|
jeweler
|
72
73
|
minitest
|
73
74
|
nokogiri (~> 1.5.0)
|
data/gemfiles/4.0.gemfile
CHANGED
data/gemfiles/4.0.gemfile.lock
CHANGED
@@ -16,7 +16,7 @@ GEM
|
|
16
16
|
multi_json (~> 1.3)
|
17
17
|
thread_safe (~> 0.1)
|
18
18
|
tzinfo (~> 0.3.37)
|
19
|
-
addressable (2.3.
|
19
|
+
addressable (2.3.7)
|
20
20
|
appraisal (1.0.2)
|
21
21
|
bundler
|
22
22
|
rake
|
@@ -25,7 +25,7 @@ GEM
|
|
25
25
|
builder (3.1.4)
|
26
26
|
faraday (0.8.9)
|
27
27
|
multipart-post (~> 1.2.0)
|
28
|
-
git (1.2.
|
28
|
+
git (1.2.9.1)
|
29
29
|
github_api (0.10.1)
|
30
30
|
addressable
|
31
31
|
faraday (~> 0.8.1)
|
@@ -33,7 +33,7 @@ GEM
|
|
33
33
|
multi_json (~> 1.4)
|
34
34
|
nokogiri (~> 1.5.2)
|
35
35
|
oauth2
|
36
|
-
hashie (3.
|
36
|
+
hashie (3.4.0)
|
37
37
|
highline (1.6.21)
|
38
38
|
i18n (0.6.11)
|
39
39
|
jeweler (2.0.1)
|
@@ -45,8 +45,8 @@ GEM
|
|
45
45
|
nokogiri (>= 1.5.10)
|
46
46
|
rake
|
47
47
|
rdoc
|
48
|
-
json (1.8.
|
49
|
-
jwt (1.2.
|
48
|
+
json (1.8.2)
|
49
|
+
jwt (1.2.1)
|
50
50
|
minitest (4.7.5)
|
51
51
|
multi_json (1.10.1)
|
52
52
|
multi_xml (0.5.5)
|
@@ -58,14 +58,14 @@ GEM
|
|
58
58
|
multi_json (~> 1.3)
|
59
59
|
multi_xml (~> 0.5)
|
60
60
|
rack (~> 1.2)
|
61
|
-
rack (1.
|
61
|
+
rack (1.6.0)
|
62
62
|
rake (10.4.2)
|
63
63
|
rdoc (4.2.0)
|
64
64
|
json (~> 1.4)
|
65
65
|
sqlite3 (1.3.10)
|
66
66
|
thor (0.19.1)
|
67
67
|
thread_safe (0.3.4)
|
68
|
-
tzinfo (0.3.
|
68
|
+
tzinfo (0.3.43)
|
69
69
|
|
70
70
|
PLATFORMS
|
71
71
|
ruby
|
@@ -73,6 +73,7 @@ PLATFORMS
|
|
73
73
|
DEPENDENCIES
|
74
74
|
activerecord (~> 4.0.0)
|
75
75
|
appraisal
|
76
|
+
i18n (~> 0.6.5)
|
76
77
|
jeweler
|
77
78
|
minitest
|
78
79
|
nokogiri (~> 1.5.0)
|
data/gemfiles/4.1.gemfile
CHANGED
data/gemfiles/4.1.gemfile.lock
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
-
activemodel (4.1.
|
5
|
-
activesupport (= 4.1.
|
4
|
+
activemodel (4.1.9)
|
5
|
+
activesupport (= 4.1.9)
|
6
6
|
builder (~> 3.1)
|
7
|
-
activerecord (4.1.
|
8
|
-
activemodel (= 4.1.
|
9
|
-
activesupport (= 4.1.
|
7
|
+
activerecord (4.1.9)
|
8
|
+
activemodel (= 4.1.9)
|
9
|
+
activesupport (= 4.1.9)
|
10
10
|
arel (~> 5.0.0)
|
11
|
-
activesupport (4.1.
|
11
|
+
activesupport (4.1.9)
|
12
12
|
i18n (~> 0.6, >= 0.6.9)
|
13
13
|
json (~> 1.7, >= 1.7.7)
|
14
14
|
minitest (~> 5.1)
|
15
15
|
thread_safe (~> 0.1)
|
16
16
|
tzinfo (~> 1.1)
|
17
|
-
addressable (2.3.
|
17
|
+
addressable (2.3.7)
|
18
18
|
appraisal (1.0.2)
|
19
19
|
bundler
|
20
20
|
rake
|
@@ -23,7 +23,7 @@ GEM
|
|
23
23
|
builder (3.2.2)
|
24
24
|
faraday (0.8.9)
|
25
25
|
multipart-post (~> 1.2.0)
|
26
|
-
git (1.2.
|
26
|
+
git (1.2.9.1)
|
27
27
|
github_api (0.10.1)
|
28
28
|
addressable
|
29
29
|
faraday (~> 0.8.1)
|
@@ -31,7 +31,7 @@ GEM
|
|
31
31
|
multi_json (~> 1.4)
|
32
32
|
nokogiri (~> 1.5.2)
|
33
33
|
oauth2
|
34
|
-
hashie (3.
|
34
|
+
hashie (3.4.0)
|
35
35
|
highline (1.6.21)
|
36
36
|
i18n (0.6.11)
|
37
37
|
jeweler (2.0.1)
|
@@ -43,9 +43,9 @@ GEM
|
|
43
43
|
nokogiri (>= 1.5.10)
|
44
44
|
rake
|
45
45
|
rdoc
|
46
|
-
json (1.8.
|
47
|
-
jwt (1.2.
|
48
|
-
minitest (5.5.
|
46
|
+
json (1.8.2)
|
47
|
+
jwt (1.2.1)
|
48
|
+
minitest (5.5.1)
|
49
49
|
multi_json (1.10.1)
|
50
50
|
multi_xml (0.5.5)
|
51
51
|
multipart-post (1.2.0)
|
@@ -56,7 +56,7 @@ GEM
|
|
56
56
|
multi_json (~> 1.3)
|
57
57
|
multi_xml (~> 0.5)
|
58
58
|
rack (~> 1.2)
|
59
|
-
rack (1.
|
59
|
+
rack (1.6.0)
|
60
60
|
rake (10.4.2)
|
61
61
|
rdoc (4.2.0)
|
62
62
|
json (~> 1.4)
|
@@ -72,6 +72,7 @@ PLATFORMS
|
|
72
72
|
DEPENDENCIES
|
73
73
|
activerecord (~> 4.1.0)
|
74
74
|
appraisal
|
75
|
+
i18n (~> 0.6.5)
|
75
76
|
jeweler
|
76
77
|
minitest
|
77
78
|
nokogiri (~> 1.5.0)
|
data/gemfiles/4.2.gemfile
CHANGED
data/gemfiles/4.2.gemfile.lock
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
-
activemodel (4.2.0
|
5
|
-
activesupport (= 4.2.0
|
4
|
+
activemodel (4.2.0)
|
5
|
+
activesupport (= 4.2.0)
|
6
6
|
builder (~> 3.1)
|
7
|
-
activerecord (4.2.0
|
8
|
-
activemodel (= 4.2.0
|
9
|
-
activesupport (= 4.2.0
|
7
|
+
activerecord (4.2.0)
|
8
|
+
activemodel (= 4.2.0)
|
9
|
+
activesupport (= 4.2.0)
|
10
10
|
arel (~> 6.0)
|
11
|
-
activesupport (4.2.0
|
12
|
-
i18n (
|
11
|
+
activesupport (4.2.0)
|
12
|
+
i18n (~> 0.7)
|
13
13
|
json (~> 1.7, >= 1.7.7)
|
14
14
|
minitest (~> 5.1)
|
15
|
-
thread_safe (~> 0.
|
15
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
16
16
|
tzinfo (~> 1.1)
|
17
|
-
addressable (2.3.
|
17
|
+
addressable (2.3.7)
|
18
18
|
appraisal (1.0.2)
|
19
19
|
bundler
|
20
20
|
rake
|
@@ -23,7 +23,7 @@ GEM
|
|
23
23
|
builder (3.2.2)
|
24
24
|
faraday (0.8.9)
|
25
25
|
multipart-post (~> 1.2.0)
|
26
|
-
git (1.2.
|
26
|
+
git (1.2.9.1)
|
27
27
|
github_api (0.10.1)
|
28
28
|
addressable
|
29
29
|
faraday (~> 0.8.1)
|
@@ -31,9 +31,9 @@ GEM
|
|
31
31
|
multi_json (~> 1.4)
|
32
32
|
nokogiri (~> 1.5.2)
|
33
33
|
oauth2
|
34
|
-
hashie (3.
|
34
|
+
hashie (3.4.0)
|
35
35
|
highline (1.6.21)
|
36
|
-
i18n (0.7.0
|
36
|
+
i18n (0.7.0)
|
37
37
|
jeweler (2.0.1)
|
38
38
|
builder
|
39
39
|
bundler (>= 1.0)
|
@@ -43,9 +43,9 @@ GEM
|
|
43
43
|
nokogiri (>= 1.5.10)
|
44
44
|
rake
|
45
45
|
rdoc
|
46
|
-
json (1.8.
|
47
|
-
jwt (1.2.
|
48
|
-
minitest (5.5.
|
46
|
+
json (1.8.2)
|
47
|
+
jwt (1.2.1)
|
48
|
+
minitest (5.5.1)
|
49
49
|
multi_json (1.10.1)
|
50
50
|
multi_xml (0.5.5)
|
51
51
|
multipart-post (1.2.0)
|
@@ -56,7 +56,7 @@ GEM
|
|
56
56
|
multi_json (~> 1.3)
|
57
57
|
multi_xml (~> 0.5)
|
58
58
|
rack (~> 1.2)
|
59
|
-
rack (1.
|
59
|
+
rack (1.6.0)
|
60
60
|
rake (10.4.2)
|
61
61
|
rdoc (4.2.0)
|
62
62
|
json (~> 1.4)
|
@@ -70,8 +70,9 @@ PLATFORMS
|
|
70
70
|
ruby
|
71
71
|
|
72
72
|
DEPENDENCIES
|
73
|
-
activerecord (~> 4.2.0
|
73
|
+
activerecord (~> 4.2.0)
|
74
74
|
appraisal
|
75
|
+
i18n (~> 0.7.0)
|
75
76
|
jeweler
|
76
77
|
minitest
|
77
78
|
nokogiri (~> 1.5.0)
|
data/lib/deep_cloneable.rb
CHANGED
@@ -11,9 +11,7 @@ class ActiveRecord::Base
|
|
11
11
|
kopy = unless dict
|
12
12
|
dup()
|
13
13
|
else
|
14
|
-
|
15
|
-
dict[tableized_class] ||= {}
|
16
|
-
dict[tableized_class][self] ||= dup()
|
14
|
+
find_in_dict_or_dup(dict)
|
17
15
|
end
|
18
16
|
|
19
17
|
block.call(self, kopy) if block
|
@@ -39,13 +37,20 @@ class ActiveRecord::Base
|
|
39
37
|
end
|
40
38
|
|
41
39
|
if options[:include]
|
42
|
-
Array(options[:include]).each do |association,
|
43
|
-
|
44
|
-
|
40
|
+
Array(options[:include]).each do |association, conditions_or_deep_associations|
|
41
|
+
conditions = {}
|
42
|
+
|
43
|
+
if association.kind_of? Hash
|
44
|
+
conditions_or_deep_associations = association[association.keys.first]
|
45
45
|
association = association.keys.first
|
46
46
|
end
|
47
47
|
|
48
|
-
|
48
|
+
if conditions_or_deep_associations.kind_of?(Hash)
|
49
|
+
conditions[:if] = conditions_or_deep_associations.delete(:if) if conditions_or_deep_associations[:if]
|
50
|
+
conditions[:unless] = conditions_or_deep_associations.delete(:unless) if conditions_or_deep_associations[:unless]
|
51
|
+
end
|
52
|
+
|
53
|
+
dup_options = conditions_or_deep_associations.blank? ? {} : {:include => conditions_or_deep_associations}
|
49
54
|
dup_options.merge!(:except => deep_exceptions[association]) if deep_exceptions[association]
|
50
55
|
dup_options.merge!(:only => deep_onlinesses[association]) if deep_onlinesses[association]
|
51
56
|
dup_options.merge!(:dictionary => dict) if dict
|
@@ -66,23 +71,34 @@ class ActiveRecord::Base
|
|
66
71
|
association_type = association_reflection.macro
|
67
72
|
association_type = "#{association_type}_through" if association_reflection.is_a?(ActiveRecord::Reflection::ThroughReflection)
|
68
73
|
|
69
|
-
|
74
|
+
duped_object = send(
|
70
75
|
"dup_#{association_type}_association",
|
71
|
-
{ :reflection => association_reflection, :association => association, :copy => kopy, :dup_options => dup_options },
|
76
|
+
{ :reflection => association_reflection, :association => association, :copy => kopy, :conditions => conditions, :dup_options => dup_options },
|
72
77
|
&block
|
73
78
|
)
|
74
79
|
|
75
|
-
kopy.send("#{association}=",
|
80
|
+
kopy.send("#{association}=", duped_object)
|
76
81
|
end
|
77
82
|
end
|
78
83
|
|
79
84
|
return kopy
|
80
85
|
end
|
81
86
|
|
87
|
+
protected
|
88
|
+
|
89
|
+
def find_in_dict_or_dup(dict, dup_on_miss = true)
|
90
|
+
tableized_class = self.class.name.tableize.to_sym
|
91
|
+
dict[tableized_class] ||= {}
|
92
|
+
dict_val = dict[tableized_class][self]
|
93
|
+
dict_val.nil? && dup_on_miss ? dict[tableized_class][self] = dup() : dict_val
|
94
|
+
end
|
95
|
+
|
82
96
|
private
|
83
97
|
|
84
98
|
def dup_belongs_to_association options, &block
|
85
|
-
|
99
|
+
object = self.send(options[:association])
|
100
|
+
object = nil if options[:conditions].any? && evaluate_conditions(object, options[:conditions])
|
101
|
+
object && object.deep_clone(options[:dup_options], &block)
|
86
102
|
end
|
87
103
|
|
88
104
|
def dup_has_one_association options, &block
|
@@ -96,8 +112,11 @@ class ActiveRecord::Base
|
|
96
112
|
reflection.foreign_key.to_s == primary_key_name && reflection != options[:reflection]
|
97
113
|
end.try(:name)
|
98
114
|
|
99
|
-
self.send(options[:association])
|
100
|
-
|
115
|
+
objects = self.send(options[:association])
|
116
|
+
objects = objects.select{|object| evaluate_conditions(object, options[:conditions]) } if options[:conditions].any?
|
117
|
+
|
118
|
+
objects.collect do |object|
|
119
|
+
tmp = object.deep_clone(options[:dup_options], &block)
|
101
120
|
tmp.send("#{primary_key_name}=", nil)
|
102
121
|
tmp.send("#{reverse_association_name.to_s}=", options[:copy]) if reverse_association_name
|
103
122
|
tmp
|
@@ -121,12 +140,24 @@ class ActiveRecord::Base
|
|
121
140
|
(reflection.macro == options[:macro]) && (reflection.association_foreign_key.to_s == options[:primary_key_name])
|
122
141
|
end.try(:name)
|
123
142
|
|
124
|
-
self.send(options[:association])
|
125
|
-
|
126
|
-
|
143
|
+
objects = self.send(options[:association])
|
144
|
+
objects = objects.select{|object| evaluate_conditions(object, options[:conditions]) } if options[:conditions].any?
|
145
|
+
|
146
|
+
objects.collect do |object|
|
147
|
+
dict = options[:dup_options][:dictionary]
|
148
|
+
if(dict && object.find_in_dict_or_dup(dict, false))
|
149
|
+
object = object.deep_clone(options[:dup_options], &block)
|
150
|
+
else
|
151
|
+
object.send(reverse_association_name).target << options[:copy] if reverse_association_name
|
152
|
+
end
|
153
|
+
object
|
127
154
|
end
|
128
155
|
end
|
129
156
|
|
157
|
+
def evaluate_conditions object, conditions
|
158
|
+
(conditions[:if] && conditions[:if].call(object)) || (conditions[:unless] && !conditions[:unless].call(object))
|
159
|
+
end
|
160
|
+
|
130
161
|
class AssociationNotFoundException < StandardError; end
|
131
162
|
|
132
163
|
ActiveRecord::Base.class_eval { protected :initialize_dup } if ActiveRecord::VERSION::MAJOR == 3 && ActiveRecord::VERSION::MINOR == 1
|
data/test/models.rb
CHANGED
@@ -86,3 +86,18 @@ class StudentAssignment < ActiveRecord::Base
|
|
86
86
|
belongs_to :subject
|
87
87
|
belongs_to :student
|
88
88
|
end
|
89
|
+
|
90
|
+
class Building < ActiveRecord::Base
|
91
|
+
has_many :apartments
|
92
|
+
has_many :contractors
|
93
|
+
end
|
94
|
+
|
95
|
+
class Apartment < ActiveRecord::Base
|
96
|
+
belongs_to :building
|
97
|
+
has_and_belongs_to_many :contractors
|
98
|
+
end
|
99
|
+
|
100
|
+
class Contractor < ActiveRecord::Base
|
101
|
+
belongs_to :building
|
102
|
+
has_and_belongs_to_many :apartments
|
103
|
+
end
|
data/test/schema.rb
CHANGED
@@ -98,4 +98,23 @@ ActiveRecord::Schema.define(:version => 1) do
|
|
98
98
|
t.column :student_id, :integer
|
99
99
|
t.column :subject_id, :integer
|
100
100
|
end
|
101
|
+
|
102
|
+
create_table :buildings, :force => true do |t|
|
103
|
+
t.column :name, :string
|
104
|
+
end
|
105
|
+
|
106
|
+
create_table :apartments, :force => true do |t|
|
107
|
+
t.column :number, :string
|
108
|
+
t.column :building_id, :integer
|
109
|
+
end
|
110
|
+
|
111
|
+
create_table :contractors, :force => true do |t|
|
112
|
+
t.column :name, :string
|
113
|
+
t.column :building_id, :integer
|
114
|
+
end
|
115
|
+
|
116
|
+
create_table :apartments_contractors, :force => true do |t|
|
117
|
+
t.column :apartment_id, :integer
|
118
|
+
t.column :contractor_id, :integer
|
119
|
+
end
|
101
120
|
end
|
data/test/test_deep_cloneable.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'test_helper'
|
2
2
|
|
3
3
|
class TestDeepCloneable < MiniTest::Unit::TestCase
|
4
4
|
|
@@ -339,4 +339,50 @@ class TestDeepCloneable < MiniTest::Unit::TestCase
|
|
339
339
|
assert_equal 'John', deep_clone.mateys.first.name
|
340
340
|
end
|
341
341
|
|
342
|
+
def test_should_reject_copies_if_conditionals_are_passed
|
343
|
+
subject1 = Subject.create(:name => 'subject 1')
|
344
|
+
subject2 = Subject.create(:name => 'subject 2')
|
345
|
+
student = Student.create(:name => 'Parent', :subjects => [subject1, subject2])
|
346
|
+
|
347
|
+
deep_clone = student.deep_clone :include => { :subjects => { :if => lambda{|subject| subject.name == 'subject 2' } } }
|
348
|
+
assert_equal 1, deep_clone.subjects.size
|
349
|
+
assert_equal 'subject 2', deep_clone.subjects.first.name
|
350
|
+
|
351
|
+
deep_clone = @jack.deep_clone(:include => {
|
352
|
+
:treasures => { :gold_pieces => { :unless => lambda{|piece| piece.is_a?(Parrot) } } },
|
353
|
+
:mateys => { :if => lambda{|matey| matey.is_a?(GoldPiece) } }
|
354
|
+
})
|
355
|
+
|
356
|
+
assert deep_clone.new_record?
|
357
|
+
assert deep_clone.save
|
358
|
+
assert_equal 1, deep_clone.treasures.size
|
359
|
+
assert_equal 1, deep_clone.gold_pieces.size
|
360
|
+
assert_equal 0, deep_clone.mateys.size
|
361
|
+
|
362
|
+
end
|
363
|
+
|
364
|
+
def test_should_find_in_dict_for_habtm
|
365
|
+
apt = Apartment.create(:number => "101")
|
366
|
+
contractor = Contractor.create(:name => "contractor", :apartments => [apt])
|
367
|
+
|
368
|
+
apt.contractors = [contractor]
|
369
|
+
apt.save!
|
370
|
+
|
371
|
+
building = Building.create(:name => "Tall Building", :contractors => [contractor], :apartments => [apt])
|
372
|
+
|
373
|
+
deep_clone = building.deep_clone(:include => [
|
374
|
+
:apartments,
|
375
|
+
{
|
376
|
+
:contractors => [
|
377
|
+
:apartments
|
378
|
+
]
|
379
|
+
}
|
380
|
+
],
|
381
|
+
:use_dictionary => true
|
382
|
+
)
|
383
|
+
deep_clone.save!
|
384
|
+
|
385
|
+
assert_equal deep_clone.contractors.first.apartments.first.id, deep_clone.apartments.first.id
|
386
|
+
assert_equal deep_clone.apartments.first.contractors.first.id, deep_clone.contractors.first.id
|
387
|
+
end
|
342
388
|
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deep_cloneable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Reinier de Lange
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-03-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -30,6 +30,20 @@ dependencies:
|
|
30
30
|
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: 3.1.0
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: i18n
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 0.6.5
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 0.6.5
|
33
47
|
description: 'Extends the functionality of ActiveRecord::Base#clone to perform a deep
|
34
48
|
clone that includes user specified associations. '
|
35
49
|
email: r.j.delange@nedforce.nl
|
@@ -67,7 +81,8 @@ files:
|
|
67
81
|
- test/test_deep_cloneable.rb
|
68
82
|
- test/test_helper.rb
|
69
83
|
homepage: http://github.com/moiristo/deep_cloneable
|
70
|
-
licenses:
|
84
|
+
licenses:
|
85
|
+
- MIT
|
71
86
|
metadata: {}
|
72
87
|
post_install_message:
|
73
88
|
rdoc_options: []
|
@@ -85,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
85
100
|
version: '0'
|
86
101
|
requirements: []
|
87
102
|
rubyforge_project:
|
88
|
-
rubygems_version: 2.4.
|
103
|
+
rubygems_version: 2.4.3
|
89
104
|
signing_key:
|
90
105
|
specification_version: 4
|
91
106
|
summary: This gem gives every ActiveRecord::Base object the possibility to do a deep
|