deep_cloneable 1.3.0 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +16 -26
- data/VERSION +1 -1
- data/deep_cloneable.gemspec +5 -5
- data/lib/deep_cloneable.rb +1 -1
- data/test/schema.rb +1 -0
- data/test/test_helper.rb +0 -1
- metadata +23 -42
data/README.rdoc
CHANGED
@@ -4,61 +4,51 @@ This gem gives every ActiveRecord::Base object the possibility to do a deep clon
|
|
4
4
|
|
5
5
|
== Requirements
|
6
6
|
|
7
|
-
* Activerecord
|
7
|
+
* Activerecord 3.1, 3.2
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
* Install by adding the gem to your Gemfile
|
12
|
-
|
13
|
-
gem 'deep_cloneable'
|
14
|
-
|
15
|
-
* Rails 2:
|
9
|
+
* Rails 2.x/3.0 users, please check out the 'rails2.x-3.0' branch.
|
16
10
|
|
17
|
-
|
18
|
-
|
19
|
-
And include the gem in your apps config
|
20
|
-
|
21
|
-
config.gem 'deep_cloneable'
|
11
|
+
== Installation
|
22
12
|
|
23
|
-
*
|
13
|
+
* In your Gemfile:
|
24
14
|
|
25
|
-
|
15
|
+
gem 'deep_cloneable', '~> 1.3.1'
|
26
16
|
|
27
17
|
== Example
|
28
18
|
|
29
19
|
=== Cloning one single association
|
30
|
-
pirate.
|
20
|
+
pirate.dup :include => :mateys
|
31
21
|
|
32
22
|
=== Cloning multiple associations
|
33
|
-
pirate.
|
23
|
+
pirate.dup :include => [:mateys, :treasures]
|
34
24
|
|
35
25
|
=== Cloning really deep
|
36
|
-
pirate.
|
26
|
+
pirate.dup :include => {:treasures => :gold_pieces}
|
37
27
|
|
38
28
|
=== Cloning really deep with multiple associations
|
39
|
-
pirate.
|
29
|
+
pirate.dup :include => [:mateys, {:treasures => :gold_pieces}]
|
40
30
|
|
41
31
|
=== Cloning really deep with multiple associations and a dictionary
|
42
32
|
|
43
33
|
A dictionary ensures that models are not cloned multiple times when it is associated to nested models.
|
44
34
|
When using a dictionary, ensure recurring associations are cloned first:
|
45
35
|
|
46
|
-
pirate.
|
36
|
+
pirate.dup :include => [:mateys, {:treasures => [:matey, :gold_pieces], :use_dictionary => true }]
|
47
37
|
|
48
38
|
If this is not an option for you, it is also possible to populate the dictionary manually in advance:
|
49
39
|
|
50
40
|
dict = { :mateys => {} }
|
51
|
-
pirate.mateys.each{|m| dict[:mateys][m] = m.
|
52
|
-
pirate.
|
41
|
+
pirate.mateys.each{|m| dict[:mateys][m] = m.dup }
|
42
|
+
pirate.dup :include => [:mateys, {:treasures => [:matey, :gold_pieces], :dictionary => dict }]
|
53
43
|
|
54
44
|
=== Cloning a model without an attribute
|
55
|
-
pirate.
|
45
|
+
pirate.dup :except => :name
|
56
46
|
|
57
47
|
=== Cloning a model without multiple attributes
|
58
|
-
pirate.
|
48
|
+
pirate.dup :except => [:name, :nick_name]
|
59
49
|
|
60
50
|
=== Cloning a model without an attribute or nested multiple attributes
|
61
|
-
pirate.
|
51
|
+
pirate.dup :include => :parrot, :except => [:name, { :parrot => [:name] }]
|
62
52
|
|
63
53
|
== Contributors
|
64
54
|
|
@@ -78,4 +68,4 @@ If this is not an option for you, it is also possible to populate the dictionary
|
|
78
68
|
|
79
69
|
== Copyright
|
80
70
|
|
81
|
-
Copyright (c)
|
71
|
+
Copyright (c) 2012 Reinier de Lange. See LICENSE for details.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.3.
|
1
|
+
1.3.1
|
data/deep_cloneable.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{deep_cloneable}
|
8
|
-
s.version = "1.3.
|
8
|
+
s.version = "1.3.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = [
|
12
|
-
s.date = %q{
|
11
|
+
s.authors = [%q{Reinier de Lange}]
|
12
|
+
s.date = %q{2012-01-26}
|
13
13
|
s.description = %q{Extends the functionality of ActiveRecord::Base#clone to perform a deep clone that includes user specified associations. }
|
14
14
|
s.email = %q{r.j.delange@nedforce.nl}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -31,8 +31,8 @@ Gem::Specification.new do |s|
|
|
31
31
|
"test/test_helper.rb"
|
32
32
|
]
|
33
33
|
s.homepage = %q{http://github.com/moiristo/deep_cloneable}
|
34
|
-
s.require_paths = [
|
35
|
-
s.rubygems_version = %q{1.6
|
34
|
+
s.require_paths = [%q{lib}]
|
35
|
+
s.rubygems_version = %q{1.8.6}
|
36
36
|
s.summary = %q{This gem gives every ActiveRecord::Base object the possibility to do a deep clone.}
|
37
37
|
|
38
38
|
if s.respond_to? :specification_version then
|
data/lib/deep_cloneable.rb
CHANGED
@@ -60,7 +60,7 @@ class ActiveRecord::Base
|
|
60
60
|
if options[:except]
|
61
61
|
exceptions = options[:except].nil? ? [] : [options[:except]].flatten
|
62
62
|
exceptions.each do |attribute|
|
63
|
-
kopy.send(:write_attribute, attribute,
|
63
|
+
kopy.send(:write_attribute, attribute, self.class.column_defaults.dup[attribute.to_s]) unless attribute.kind_of?(Hash)
|
64
64
|
end
|
65
65
|
deep_exceptions = exceptions.select{|e| e.kind_of?(Hash) }.inject({}){|m,h| m.merge(h) }
|
66
66
|
end
|
data/test/schema.rb
CHANGED
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,34 +1,25 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: deep_cloneable
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.3.1
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 1
|
8
|
-
- 3
|
9
|
-
- 0
|
10
|
-
version: 1.3.0
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Reinier de Lange
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
date: 2011-07-11 00:00:00 +02:00
|
19
|
-
default_executable:
|
12
|
+
date: 2012-01-26 00:00:00.000000000 Z
|
20
13
|
dependencies: []
|
21
|
-
|
22
|
-
|
14
|
+
description: ! 'Extends the functionality of ActiveRecord::Base#clone to perform a
|
15
|
+
deep clone that includes user specified associations. '
|
23
16
|
email: r.j.delange@nedforce.nl
|
24
17
|
executables: []
|
25
|
-
|
26
18
|
extensions: []
|
27
|
-
|
28
|
-
extra_rdoc_files:
|
19
|
+
extra_rdoc_files:
|
29
20
|
- LICENSE
|
30
21
|
- README.rdoc
|
31
|
-
files:
|
22
|
+
files:
|
32
23
|
- .document
|
33
24
|
- LICENSE
|
34
25
|
- README.rdoc
|
@@ -41,39 +32,29 @@ files:
|
|
41
32
|
- test/schema.rb
|
42
33
|
- test/test_deep_cloneable.rb
|
43
34
|
- test/test_helper.rb
|
44
|
-
has_rdoc: true
|
45
35
|
homepage: http://github.com/moiristo/deep_cloneable
|
46
36
|
licenses: []
|
47
|
-
|
48
37
|
post_install_message:
|
49
38
|
rdoc_options: []
|
50
|
-
|
51
|
-
require_paths:
|
39
|
+
require_paths:
|
52
40
|
- lib
|
53
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
42
|
none: false
|
55
|
-
requirements:
|
56
|
-
- -
|
57
|
-
- !ruby/object:Gem::Version
|
58
|
-
|
59
|
-
|
60
|
-
- 0
|
61
|
-
version: "0"
|
62
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
48
|
none: false
|
64
|
-
requirements:
|
65
|
-
- -
|
66
|
-
- !ruby/object:Gem::Version
|
67
|
-
|
68
|
-
segments:
|
69
|
-
- 0
|
70
|
-
version: "0"
|
49
|
+
requirements:
|
50
|
+
- - ! '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
71
53
|
requirements: []
|
72
|
-
|
73
54
|
rubyforge_project:
|
74
|
-
rubygems_version: 1.6
|
55
|
+
rubygems_version: 1.8.6
|
75
56
|
signing_key:
|
76
57
|
specification_version: 3
|
77
|
-
summary: This gem gives every ActiveRecord::Base object the possibility to do a deep
|
58
|
+
summary: This gem gives every ActiveRecord::Base object the possibility to do a deep
|
59
|
+
clone.
|
78
60
|
test_files: []
|
79
|
-
|