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 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', :git).to_sym
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 == :rubygems
26
- gem "dm-module_name", DM_VERSION
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, :git => "http://github.com/datamapper/dm-#{module_name}.git", :branch => ENV.fetch('BRANCH', 'master')
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
+ 1.0.2
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "dm-deep_cloning"
8
- s.version = "1.0.1"
8
+ s.version = "1.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Till Schulte-Coerne"]
@@ -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
- self.class.relationships.each do |relationship|
53
- if clone_relations.keys.include?(relationship.name)
54
- case relationship
55
- when DataMapper::Associations::OneToMany::Relationship, DataMapper::Associations::ManyToMany::Relationship
56
- attributes[relationship.name] = self.send(relationship.name).map do |related_object|
57
- related_object.deep_clone(mode, clone_relations[relationship.name])
58
- end
59
- if attributes[relationship.name].empty?
60
- # Delete the atrribute if no objects need to be assigned to the relation.
61
- # dm-core seems to have a problem with Foo.new(:bars => []). Sadly
62
- # this was not reproduceable in the specs.
63
- attributes.delete(relationship.name)
64
- end
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
- elsif relationship.is_a?(DataMapper::Associations::ManyToMany::Relationship) # We always need to clone many to many relationship entrys (but not targets of the relations)
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: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 1
10
- version: 1.0.1
9
+ - 2
10
+ version: 1.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Till Schulte-Coerne