deep_cloneable 1.5.5 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZDk4MTlkNjQ2ODUzNzA4OGQyZjc3NTAxMmUxMzkwYzQxODQyZGI2MA==
4
+ OWRkNjEzMTlmOTg4YzcwNTUwYjk1ZDA0MDFkODBkNWQxZGViN2Y0ZQ==
5
5
  data.tar.gz: !binary |-
6
- ZGE2YmU4YWE5MmE2MTIzZDVlMGIwODZjMWVjMDhlY2FkMmFlMzI1Nw==
6
+ YmVhZWE1YmEwMjE1NmYwMTEwNTU3NmY1YzhlZjQ3NjJmNDRjNmVjNw==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- MjVjYmNmMDAyYjE2ODRkZjk0YjIwNmZmN2QxNjBlNDUyMGNmNjFkMmNmMmY2
10
- MTU3MTMzMWZhMTIxNGJjZmMzMjk0MTg0YzEwNzc0NmRmNTRhMmIyNjZiMjUz
11
- MTRiNmVlMmFiM2Y2NGFmZWM1MjY3YTYwYzIyM2UxYTU5OGI2MmY=
9
+ NWE2ZDU4ZjI5ZWM4NzFlYmU3MGFiMjRiOThjMmQ5NGY5NTc2ODI3NjFhNTMx
10
+ YTE1NmYxMDFiZGU2Mzg1YTQxODllYzczOWEzMDNmYWEwMjdlNjE4MDU0ZDhm
11
+ MWVkYzU0YmUyYTE3YWI4MzFkZTk4NDI4MTQ1OGVhZmQxYzJkNmU=
12
12
  data.tar.gz: !binary |-
13
- MzE3MDA0MjE2ZTYyZWVkNTA5MmFhZWNhMjg0MDY0ZGE4YTA5NzAwMDg5NDk1
14
- NDc2NGFjNzY1M2ZmNzg5ZWNjMmQ0OTRlNGM5NDZmODg3ZmY4Y2VmNmFiNGJk
15
- ZDVlYmQ1MmRhMWUwMGEyM2ZiYTcyZGZhNDgxMTQ4N2I1ZGM2YzQ=
13
+ NmQzZjZmOGM4MDI5NWZkN2Y2MWE2NmJhMTVkMzkyNjUxZWE5MDE0Y2QyYzEy
14
+ ZjNlNDMzNWRiYmFkNTY4NmUyYmFjZmIwNThlMDM3ODcwZTEyN2Y1NjRmNDBl
15
+ ODUwNDk4MDUxYjBlMTMwYmIzYThmYTI4NDE2NWUyMjk1MWJmNTI=
data/Gemfile.lock CHANGED
@@ -1,26 +1,31 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- activemodel (3.1.12)
5
- activesupport (= 3.1.12)
6
- builder (~> 3.0.0)
7
- i18n (~> 0.6)
8
- activerecord (3.1.12)
9
- activemodel (= 3.1.12)
10
- activesupport (= 3.1.12)
11
- arel (~> 2.2.3)
12
- tzinfo (~> 0.3.29)
13
- activesupport (3.1.12)
14
- multi_json (~> 1.0)
4
+ activemodel (4.0.1)
5
+ activesupport (= 4.0.1)
6
+ builder (~> 3.1.0)
7
+ activerecord (4.0.1)
8
+ activemodel (= 4.0.1)
9
+ activerecord-deprecated_finders (~> 1.0.2)
10
+ activesupport (= 4.0.1)
11
+ arel (~> 4.0.0)
12
+ activerecord-deprecated_finders (1.0.3)
13
+ activesupport (4.0.1)
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)
15
19
  addressable (2.3.5)
16
20
  appraisal (0.5.2)
17
21
  bundler
18
22
  rake
19
- arel (2.2.3)
20
- builder (3.0.4)
23
+ arel (4.0.1)
24
+ atomic (1.1.14)
25
+ builder (3.1.4)
21
26
  faraday (0.8.8)
22
27
  multipart-post (~> 1.2.0)
23
- git (1.2.5)
28
+ git (1.2.6)
24
29
  github_api (0.10.1)
25
30
  addressable
26
31
  faraday (~> 0.8.1)
@@ -28,11 +33,11 @@ GEM
28
33
  multi_json (~> 1.4)
29
34
  nokogiri (~> 1.5.2)
30
35
  oauth2
31
- hashie (2.0.5)
32
- highline (1.6.19)
36
+ hashie (2.0.4)
37
+ highline (1.6.20)
33
38
  httpauth (0.2.0)
34
- i18n (0.6.4)
35
- jeweler (1.8.6)
39
+ i18n (0.6.5)
40
+ jeweler (1.8.8)
36
41
  builder
37
42
  bundler (~> 1.0)
38
43
  git (>= 1.2.5)
@@ -41,10 +46,11 @@ GEM
41
46
  nokogiri (= 1.5.10)
42
47
  rake
43
48
  rdoc
44
- json (1.8.0)
49
+ json (1.8.1)
45
50
  jwt (0.1.8)
46
51
  multi_json (>= 1.5)
47
- multi_json (1.7.9)
52
+ minitest (4.7.5)
53
+ multi_json (1.8.2)
48
54
  multi_xml (0.5.5)
49
55
  multipart-post (1.2.0)
50
56
  nokogiri (1.5.10)
@@ -59,8 +65,10 @@ GEM
59
65
  rake (10.1.0)
60
66
  rdoc (4.0.1)
61
67
  json (~> 1.4)
62
- sqlite3 (1.3.7)
63
- tzinfo (0.3.37)
68
+ sqlite3 (1.3.8)
69
+ thread_safe (0.1.3)
70
+ atomic
71
+ tzinfo (0.3.38)
64
72
 
65
73
  PLATFORMS
66
74
  ruby
data/README.rdoc CHANGED
@@ -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.5'
19
+ gem 'deep_cloneable', '~> 1.6.0'
20
20
 
21
21
  == Example
22
22
 
@@ -52,7 +52,7 @@ When an object isn't found in the dictionary, it will be populated. By passing i
52
52
 
53
53
  === Cloning a model without multiple attributes
54
54
  pirate.dup :except => [:name, :nick_name]
55
-
55
+
56
56
  === Cloning a model without an attribute or nested multiple attributes
57
57
  pirate.dup :include => :parrot, :except => [:name, { :parrot => [:name] }]
58
58
 
@@ -63,20 +63,15 @@ When an object isn't found in the dictionary, it will be populated. By passing i
63
63
 
64
64
  === Cloning without validations
65
65
  pirate.dup :include => {:treasures => :gold_pieces}, :validate => false
66
+
67
+ === Cloning a model with only explicitly assigned attribute
68
+ pirate.dup :only => :name
66
69
 
67
- == Contributors
68
-
69
- * Michael He
70
- * Indrek Juhkam
71
- * Mart Karu
72
- * Rolf Timmermans
73
- * Ilya Kuzmin
74
- * zozi
75
- * fractious
76
- * Georges Gabereau
77
- * Christophe Belpaire
78
- * Kevin Carter
79
- * fokcep
70
+ === Cloning a model with only multiple explicitly assigned attributes
71
+ pirate.dup :only => [:name, :nick_name]
72
+
73
+ === Cloning a model with explicitly assigned attributes or nested multiple attributes
74
+ pirate.dup :include => :parrot, :only => [:name, { :parrot => [:name] }]
80
75
 
81
76
  == Note on Patches/Pull Requests
82
77
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.5.5
1
+ 1.6.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "deep_cloneable"
8
- s.version = "1.5.5"
8
+ s.version = "1.6.0"
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-08-28"
12
+ s.date = "2013-11-05"
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 = [
@@ -42,6 +42,17 @@ class ActiveRecord::Base
42
42
  deep_exceptions = exceptions.select{|e| e.kind_of?(Hash) }.inject({}){|m,h| m.merge(h) }
43
43
  end
44
44
 
45
+ deep_onlinesses = {}
46
+ if options[:only]
47
+ onlinesses = options[:only].nil? ? [] : [options[:only]].flatten
48
+ object_attrs = kopy.attributes.keys.collect{ |s| s.to_sym }
49
+ exceptions = object_attrs - onlinesses
50
+ exceptions.each do |attribute|
51
+ kopy.send(:write_attribute, attribute, self.class.column_defaults.dup[attribute.to_s]) unless attribute.kind_of?(Hash)
52
+ end
53
+ deep_onlinesses = onlinesses.select{|e| e.kind_of?(Hash) }.inject({}){|m,h| m.merge(h) }
54
+ end
55
+
45
56
  if options[:include]
46
57
  Array(options[:include]).each do |association, deep_associations|
47
58
  if (association.kind_of? Hash)
@@ -51,6 +62,7 @@ class ActiveRecord::Base
51
62
 
52
63
  dup_options = deep_associations.blank? ? {} : {:include => deep_associations}
53
64
  dup_options.merge!(:except => deep_exceptions[association]) if deep_exceptions[association]
65
+ dup_options.merge!(:only => deep_onlinesses[association]) if deep_onlinesses[association]
54
66
  dup_options.merge!(:dictionary => dict) if dict
55
67
 
56
68
  association_reflection = self.class.reflect_on_association(association)
data/test/schema.rb CHANGED
@@ -9,6 +9,7 @@ ActiveRecord::Schema.define(:version => 1) do
9
9
 
10
10
  create_table :parrots, :force => true do |t|
11
11
  t.column :name, :string
12
+ t.column :age, :integer
12
13
  t.column :pirate_id, :integer
13
14
  end
14
15
 
@@ -4,7 +4,7 @@ class TestDeepCloneable < Test::Unit::TestCase
4
4
 
5
5
  def setup
6
6
  @jack = Pirate.create(:name => 'Jack Sparrow', :nick_name => 'Captain Jack', :age => 30)
7
- @polly = Parrot.create(:name => 'Polly', :pirate => @jack)
7
+ @polly = Parrot.create(:name => 'Polly', :age => 2, :pirate => @jack)
8
8
  @john = Matey.create(:name => 'John', :pirate => @jack)
9
9
  @treasure = Treasure.create(:found_at => 'Isla del Muerte', :pirate => @jack, :matey => @john)
10
10
  @gold_piece = GoldPiece.create(:treasure => @treasure)
@@ -29,6 +29,28 @@ class TestDeepCloneable < Test::Unit::TestCase
29
29
  assert_equal @jack.age, dup.age
30
30
  end
31
31
 
32
+ def test_single_dup_onliness
33
+ dup = @jack.dup(:only => :name)
34
+ assert dup.new_record?
35
+ assert dup.save
36
+ assert_equal @jack.name, dup.name
37
+ assert_equal 'no nickname', dup.nick_name
38
+ assert_nil dup.age
39
+ assert_nil dup.ship_id
40
+ assert_nil dup.ship_type
41
+ end
42
+
43
+ def test_multiple_dup_onliness
44
+ dup = @jack.dup(:only => [:name, :nick_name])
45
+ assert dup.new_record?
46
+ assert dup.save
47
+ assert_equal @jack.name, dup.name
48
+ assert_equal @jack.nick_name, dup.nick_name
49
+ assert_nil dup.age
50
+ assert_nil dup.ship_id
51
+ assert_nil dup.ship_type
52
+ end
53
+
32
54
  def test_single_include_association
33
55
  dup = @jack.dup(:include => :mateys)
34
56
  assert dup.new_record?
@@ -106,10 +128,20 @@ class TestDeepCloneable < Test::Unit::TestCase
106
128
  assert dup.new_record?
107
129
  assert dup.save
108
130
  assert_not_equal dup.parrot, @jack.parrot
131
+ assert_equal dup.parrot.age, @jack.parrot.age
109
132
  assert_not_nil @jack.parrot.name
110
133
  assert_nil dup.parrot.name
111
134
  end
112
135
 
136
+ def test_should_pass_nested_onlinesses
137
+ dup = @jack.dup(:include => :parrot, :only => [:name, { :parrot => [:name] }])
138
+ assert dup.new_record?
139
+ assert dup.save
140
+ assert_not_equal dup.parrot, @jack.parrot
141
+ assert_equal dup.parrot.name, @jack.parrot.name
142
+ assert_nil dup.parrot.age
143
+ end
144
+
113
145
  def test_should_not_double_dup_when_using_dictionary
114
146
  current_matey_count = Matey.count
115
147
  dup = @jack.dup(:include => [:mateys, { :treasures => :matey }], :use_dictionary => true)
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: 1.5.5
4
+ version: 1.6.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: 2013-08-28 00:00:00.000000000 Z
11
+ date: 2013-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement