dm-deep_cloning 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +4 -4
- data/VERSION +1 -1
- data/dm-deep_cloning.gemspec +1 -1
- data/lib/dm-deep_cloning.rb +17 -19
- data/spec/dm-deep_cloning_spec.rb +0 -6
- metadata +3 -3
data/Gemfile
CHANGED
@@ -14,7 +14,7 @@
|
|
14
14
|
# See the License for the specific language governing permissions and
|
15
15
|
# limitations under the License.
|
16
16
|
|
17
|
-
SOURCE = ENV.fetch('SOURCE', :
|
17
|
+
SOURCE = ENV.fetch('SOURCE', :rubygems).to_sym
|
18
18
|
|
19
19
|
DM_VERSION = '~> 1.2.0'
|
20
20
|
|
@@ -22,12 +22,12 @@ DO_VERSION = '~> 0.10.6'
|
|
22
22
|
DM_DO_ADAPTERS = %w[ sqlite postgres mysql oracle sqlserver ]
|
23
23
|
|
24
24
|
def dm(module_name)
|
25
|
-
if SOURCE == :
|
26
|
-
gem "dm
|
25
|
+
if SOURCE == :git
|
26
|
+
gem "dm-#{module_name}", DM_VERSION, :git => "http://github.com/datamapper/dm-#{module_name}.git", :branch => ENV.fetch('BRANCH', 'master')
|
27
27
|
elsif SOURCE == :path
|
28
28
|
gem "dm-#{module_name}", DM_VERSION, :path => Pathname(__FILE__).dirname.parent
|
29
29
|
else
|
30
|
-
gem "dm-#{module_name}", DM_VERSION
|
30
|
+
gem "dm-#{module_name}", DM_VERSION
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.2
|
data/dm-deep_cloning.gemspec
CHANGED
data/lib/dm-deep_cloning.rb
CHANGED
@@ -49,26 +49,24 @@ module DataMapper
|
|
49
49
|
self.class.properties[k].key? || k.to_s =~ /^(updated|created)_(at|on)$/
|
50
50
|
}
|
51
51
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
when DataMapper::Associations::ManyToOne::Relationship
|
66
|
-
attributes[relationship.name] = self.send(relationship.name).deep_clone(mode, clone_relations[relationship.name])
|
67
|
-
else
|
68
|
-
raise "Deep cloning failed: Unknown relationship '#{relationship.class}' for relation '#{relationship.name}' in '#{self.class}'"
|
52
|
+
clone_relations.keys.each do |relationship_name|
|
53
|
+
relationship = self.class.relationships[relationship_name]
|
54
|
+
|
55
|
+
case relationship
|
56
|
+
when DataMapper::Associations::OneToMany::Relationship, DataMapper::Associations::ManyToMany::Relationship
|
57
|
+
attributes[relationship.name] = self.send(relationship.name).map do |related_object|
|
58
|
+
related_object.deep_clone(mode, clone_relations[relationship.name])
|
59
|
+
end
|
60
|
+
if attributes[relationship.name].empty?
|
61
|
+
# Delete the atrribute if no objects need to be assigned to the relation.
|
62
|
+
# dm-core seems to have a problem with Foo.new(:bars => []). Sadly
|
63
|
+
# this was not reproduceable in the specs.
|
64
|
+
attributes.delete(relationship.name)
|
69
65
|
end
|
70
|
-
|
71
|
-
attributes[relationship.name] = self.send(relationship.name)
|
66
|
+
when DataMapper::Associations::ManyToOne::Relationship
|
67
|
+
attributes[relationship.name] = self.send(relationship.name).deep_clone(mode, clone_relations[relationship.name])
|
68
|
+
else
|
69
|
+
raise "Deep cloning failed: Unknown relationship '#{relationship.class}' for relation '#{relationship.name}' in '#{self.class}'"
|
72
70
|
end
|
73
71
|
end
|
74
72
|
|
@@ -53,12 +53,6 @@ describe DataMapper::DeepCloning do
|
|
53
53
|
cloned_post.blog.id.should be(@post1.blog.id)
|
54
54
|
end
|
55
55
|
|
56
|
-
it "should handle many to many relations" do
|
57
|
-
cloned_post = @post2.deep_clone(:create)
|
58
|
-
|
59
|
-
cloned_post.related_posts.map(&:id).should =~ [@post1.id]
|
60
|
-
end
|
61
|
-
|
62
56
|
it "should not clone timestamps" do
|
63
57
|
cloned_post = @post2.deep_clone(:create)
|
64
58
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dm-deep_cloning
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 2
|
10
|
+
version: 1.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Till Schulte-Coerne
|