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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7a7680d6c3370d3475be4b547fbf43ffc7ea8226
4
- data.tar.gz: 2677691cbdaf728802ef7d1b3f43f4d6d4f276ca
3
+ metadata.gz: 31259626578b39e7deaa9ae9af33f0cc5da9bfbe
4
+ data.tar.gz: 959e624306e8e560775e6e851e1c54eee032d2f3
5
5
  SHA512:
6
- metadata.gz: b815aae3d32934a3d1bd8c477f22a2f872943f2d056276ab1e1450ff6ff5f87c3499169af4c57530cdf4db869093f7b49d03ea5c0b6f585b0b1b23e8d7ae3b3c
7
- data.tar.gz: 719fd3c785ebea996fbf61095e9703fe5ba0df685278ed2276f768f05e3fe9dfe61680fa919b4f89b30fdc89613baa5f2088e6c5483ed2ba13faff950be0dfcc
6
+ metadata.gz: db538e17fe17aa1c3b1668dba797211b88b8535d73d7aef46276c706d59acd915d82943453bfab26423e71b89d9f01ccc8a8659f4844751becd895757da63cde
7
+ data.tar.gz: 6599bdef23fe3a4780e621b88cc18dea62e2dc7bce0188cb7c10ae24a17d9fe730bf64ef22f824b377a2ecfb0dc01fe3eac9c24be29a135e8e73bdf2fea8ef20
data/Appraisals CHANGED
@@ -15,5 +15,6 @@ appraise '4.1' do
15
15
  end
16
16
 
17
17
  appraise '4.2' do
18
- gem 'activerecord', '~> 4.2.0.rc3'
18
+ gem 'activerecord', '~> 4.2.0'
19
+ gem 'i18n', '~> 0.7.0'
19
20
  end
data/Gemfile CHANGED
@@ -1,6 +1,7 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
3
  gem 'activerecord', '>= 3.1.0', '< 5.0.0'
4
+ gem 'i18n', '~> 0.6.5'
4
5
 
5
6
  gem 'minitest', :group => :test
6
7
  gem 'appraisal', :group => :test
data/Gemfile.lock CHANGED
@@ -1,29 +1,31 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- activemodel (4.2.0.rc3)
5
- activesupport (= 4.2.0.rc3)
6
- builder (~> 3.1)
7
- activerecord (4.2.0.rc3)
8
- activemodel (= 4.2.0.rc3)
9
- activesupport (= 4.2.0.rc3)
10
- arel (~> 6.0)
11
- activesupport (4.2.0.rc3)
12
- i18n (>= 0.7.0.beta1, < 0.8)
13
- json (~> 1.7, >= 1.7.7)
14
- minitest (~> 5.1)
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 (~> 1.1)
17
- addressable (2.3.6)
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 (6.0.0)
23
- builder (3.2.2)
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.8)
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.3.2)
36
+ hashie (3.4.0)
35
37
  highline (1.6.21)
36
- i18n (0.7.0.beta1)
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.1)
47
- jwt (1.2.0)
48
- minitest (5.5.0)
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.5.2)
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 (1.2.2)
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
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014 Reinier de Lange
1
+ Copyright (c) 2015 Reinier de Lange
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
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.0.rc3
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.2'
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) 2014 Reinier de Lange. See LICENSE for details.
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.2
1
+ 2.1.0
@@ -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.2 ruby lib
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.2"
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 = "2014-12-17"
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.rubygems_version = "2.4.2"
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
@@ -3,6 +3,7 @@
3
3
  source "http://rubygems.org"
4
4
 
5
5
  gem "activerecord", "~> 3.1.0"
6
+ gem "i18n", "~> 0.6.5"
6
7
  gem "minitest", :group => :test
7
8
  gem "appraisal", :group => :test
8
9
  gem "sqlite3", :group => :test
@@ -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.6)
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.8)
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.3.2)
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.1)
45
- jwt (1.2.0)
46
- minitest (5.5.0)
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.5.2)
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.42)
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
@@ -3,6 +3,7 @@
3
3
  source "http://rubygems.org"
4
4
 
5
5
  gem "activerecord", "~> 3.2.0"
6
+ gem "i18n", "~> 0.6.5"
6
7
  gem "minitest", :group => :test
7
8
  gem "appraisal", :group => :test
8
9
  gem "sqlite3", :group => :test
@@ -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.6)
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.8)
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.3.2)
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.1)
45
- jwt (1.2.0)
46
- minitest (5.5.0)
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.5.2)
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.42)
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
@@ -3,6 +3,7 @@
3
3
  source "http://rubygems.org"
4
4
 
5
5
  gem "activerecord", "~> 4.0.0"
6
+ gem "i18n", "~> 0.6.5"
6
7
  gem "minitest", :group => :test
7
8
  gem "appraisal", :group => :test
8
9
  gem "sqlite3", :group => :test
@@ -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.6)
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.8)
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.3.2)
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.1)
49
- jwt (1.2.0)
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.5.2)
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.42)
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
@@ -3,6 +3,7 @@
3
3
  source "http://rubygems.org"
4
4
 
5
5
  gem "activerecord", "~> 4.1.0"
6
+ gem "i18n", "~> 0.6.5"
6
7
  gem "minitest", :group => :test
7
8
  gem "appraisal", :group => :test
8
9
  gem "sqlite3", :group => :test
@@ -1,20 +1,20 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- activemodel (4.1.8)
5
- activesupport (= 4.1.8)
4
+ activemodel (4.1.9)
5
+ activesupport (= 4.1.9)
6
6
  builder (~> 3.1)
7
- activerecord (4.1.8)
8
- activemodel (= 4.1.8)
9
- activesupport (= 4.1.8)
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.8)
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.6)
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.8)
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.3.2)
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.1)
47
- jwt (1.2.0)
48
- minitest (5.5.0)
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.5.2)
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
@@ -2,7 +2,8 @@
2
2
 
3
3
  source "http://rubygems.org"
4
4
 
5
- gem "activerecord", "~> 4.2.0.rc3"
5
+ gem "activerecord", "~> 4.2.0"
6
+ gem "i18n", "~> 0.7.0"
6
7
  gem "minitest", :group => :test
7
8
  gem "appraisal", :group => :test
8
9
  gem "sqlite3", :group => :test
@@ -1,20 +1,20 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- activemodel (4.2.0.rc3)
5
- activesupport (= 4.2.0.rc3)
4
+ activemodel (4.2.0)
5
+ activesupport (= 4.2.0)
6
6
  builder (~> 3.1)
7
- activerecord (4.2.0.rc3)
8
- activemodel (= 4.2.0.rc3)
9
- activesupport (= 4.2.0.rc3)
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.rc3)
12
- i18n (>= 0.7.0.beta1, < 0.8)
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.1)
15
+ thread_safe (~> 0.3, >= 0.3.4)
16
16
  tzinfo (~> 1.1)
17
- addressable (2.3.6)
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.8)
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.3.2)
34
+ hashie (3.4.0)
35
35
  highline (1.6.21)
36
- i18n (0.7.0.beta1)
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.1)
47
- jwt (1.2.0)
48
- minitest (5.5.0)
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.5.2)
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.rc3)
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)
@@ -11,9 +11,7 @@ class ActiveRecord::Base
11
11
  kopy = unless dict
12
12
  dup()
13
13
  else
14
- tableized_class = self.class.name.tableize.to_sym
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, deep_associations|
43
- if (association.kind_of? Hash)
44
- deep_associations = association[association.keys.first]
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
- dup_options = deep_associations.blank? ? {} : {:include => deep_associations}
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
- cloned_object = send(
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}=", cloned_object)
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
- self.send(options[:association]) && self.send(options[:association]).deep_clone(options[:dup_options], &block)
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]).collect do |obj|
100
- tmp = obj.deep_clone(options[:dup_options], &block)
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]).collect do |obj|
125
- obj.send(reverse_association_name).target << options[:copy] if reverse_association_name
126
- obj
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
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/test_helper'
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
@@ -1,5 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'yaml'
3
+
4
+ gem 'minitest'
3
5
  require 'minitest/autorun'
4
6
 
5
7
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
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.2
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: 2014-12-17 00:00:00.000000000 Z
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.2
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