activerecord_cloneable 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/activerecord_cloneable.gemspec +1 -1
- data/lib/active_record/cloneable.rb +11 -9
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c81b1fbf2c02217309e3efbf4c4d8d6f9e7997a
|
4
|
+
data.tar.gz: 066b580b8d8818ddbb6b8294e7dc8c5113286795
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2aeddf99d7f62ebd5a3407834574d0a1bfc7143477ef6262a622fbb1dd5acf0b6e7221e541b992dd03ab47fdf9b17891092a1ac1304d5fa0976a3c845baab3c1
|
7
|
+
data.tar.gz: 34b9a54f131a30226161d79cb7d5be772b91503d6a9c92f2e4f32945b3ccd004bd41de2e482b5f649fa48cfba70bda01cb7fb8bb2c0742062d68fa563b0c5f47
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'activerecord_cloneable'
|
3
|
-
s.version = '0.3.
|
3
|
+
s.version = '0.3.2'
|
4
4
|
s.summary = "A library to help clone active records - that is, generate active new record objects with the data copied from an existing record."
|
5
5
|
s.authors = ["Adam Palmblad"]
|
6
6
|
s.email = 'apalmblad@gmail.com'
|
@@ -44,15 +44,17 @@ module ActiveRecord::Cloneable
|
|
44
44
|
relations.each do |parent_relation|
|
45
45
|
obj = send( parent_relation.name )
|
46
46
|
next if obj.nil?
|
47
|
+
next if args[:skipped_children].include?( obj )
|
47
48
|
if args[:shared_parent_relations].include?( parent_relation.name.to_sym )
|
48
49
|
cloned_record.send( "#{parent_relation.name}=", obj )
|
49
50
|
elsif !args[:cloned_parents].include?( obj )
|
50
51
|
# We don't know what the parent calls this child.
|
51
52
|
begin
|
52
|
-
rec = obj.clone_record( :
|
53
|
-
:
|
54
|
-
:
|
55
|
-
:
|
53
|
+
rec = obj.clone_record( skipped_children: args[:skipped_children] + [self],
|
54
|
+
cloned_parents: args[:cloned_parents] + [self],
|
55
|
+
skipped_child_relations: find_applicable_clone_args( parent_relation.name, args[:skipped_child_relations] ),
|
56
|
+
skipped_parent_relations: find_applicable_clone_args( parent_relation.name, args[:skipped_parent_relations] ),
|
57
|
+
shared_parent_relations: find_applicable_clone_args( parent_relation.name, args[:shared_parent_relations] )
|
56
58
|
)
|
57
59
|
rescue NoMethodError
|
58
60
|
raise "#{obj.class.name} objects do not know how to clone themselves; they should be marked as cloneable or skipped."
|
@@ -110,8 +112,8 @@ module ActiveRecord::Cloneable
|
|
110
112
|
kids.each do |child_record|
|
111
113
|
next if args[:skipped_children].include?( child_record )
|
112
114
|
cloned_child_record = kids.build
|
113
|
-
child_args = { :
|
114
|
-
:
|
115
|
+
child_args = { cloned_parents: args[:cloned_parents] + [self], attributes: {}, object: cloned_child_record,
|
116
|
+
skipped_child_relations: find_applicable_clone_args( child_relation.name, args[:skipped_child_relations] ) }
|
115
117
|
#if child_relation.macro == :has_many ||child_relation.macro == :has_one
|
116
118
|
# child_args[:attributes][child_relation.primary_key_name.to_sym] = nil
|
117
119
|
#end
|
@@ -130,9 +132,9 @@ module ActiveRecord::Cloneable
|
|
130
132
|
next if kid.nil?
|
131
133
|
next if args[:skipped_children].include?( kid )
|
132
134
|
cloned_child_record = kid.build
|
133
|
-
child_args = { :
|
134
|
-
:
|
135
|
-
:
|
135
|
+
child_args = { cloned_parents: args[:cloned_parents] + [self],
|
136
|
+
attributes: {}, object: cloned_child_record,
|
137
|
+
skipped_child_relations: args[:skipped_child_relations].find_all{ |x| x.is_a?( Hash ) && x[child_relation.name.to_sym] }.map{ |x| x.values }.flatten }
|
136
138
|
begin
|
137
139
|
cloned_child_record = kid.clone_record( child_args )
|
138
140
|
cloned_record.send( "#{child_relation.name}=", cloned_child_record )
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord_cloneable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Palmblad
|
@@ -92,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
92
|
version: '0'
|
93
93
|
requirements: []
|
94
94
|
rubyforge_project:
|
95
|
-
rubygems_version: 2.
|
95
|
+
rubygems_version: 2.5.1
|
96
96
|
signing_key:
|
97
97
|
specification_version: 4
|
98
98
|
summary: A library to help clone active records - that is, generate active new record
|