ar_merge 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +6 -0
- data/Gemfile.lock +45 -0
- data/Rakefile +20 -18
- data/{README.markdown → Readme.md} +5 -5
- data/ar_merge.gemspec +10 -49
- data/lib/ar_merge.rb +3 -4
- data/lib/ar_merge/version.rb +3 -0
- data/spec/ar_merge_spec.rb +3 -3
- data/spec/setup_test_model.rb +4 -1
- data/spec/spec_helper.rb +2 -3
- metadata +52 -48
- data/VERSION +0 -1
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
ar_merge (0.2.0)
|
5
|
+
activerecord
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activemodel (3.2.2)
|
11
|
+
activesupport (= 3.2.2)
|
12
|
+
builder (~> 3.0.0)
|
13
|
+
activerecord (3.2.2)
|
14
|
+
activemodel (= 3.2.2)
|
15
|
+
activesupport (= 3.2.2)
|
16
|
+
arel (~> 3.0.2)
|
17
|
+
tzinfo (~> 0.3.29)
|
18
|
+
activesupport (3.2.2)
|
19
|
+
i18n (~> 0.6)
|
20
|
+
multi_json (~> 1.0)
|
21
|
+
arel (3.0.2)
|
22
|
+
builder (3.0.0)
|
23
|
+
diff-lcs (1.1.3)
|
24
|
+
i18n (0.6.0)
|
25
|
+
multi_json (1.3.4)
|
26
|
+
rake (0.9.2.2)
|
27
|
+
rspec (2.9.0)
|
28
|
+
rspec-core (~> 2.9.0)
|
29
|
+
rspec-expectations (~> 2.9.0)
|
30
|
+
rspec-mocks (~> 2.9.0)
|
31
|
+
rspec-core (2.9.0)
|
32
|
+
rspec-expectations (2.9.0)
|
33
|
+
diff-lcs (~> 1.1.3)
|
34
|
+
rspec-mocks (2.9.0)
|
35
|
+
sqlite3 (1.3.6)
|
36
|
+
tzinfo (0.3.33)
|
37
|
+
|
38
|
+
PLATFORMS
|
39
|
+
ruby
|
40
|
+
|
41
|
+
DEPENDENCIES
|
42
|
+
ar_merge!
|
43
|
+
rake
|
44
|
+
rspec (~> 2)
|
45
|
+
sqlite3
|
data/Rakefile
CHANGED
@@ -1,20 +1,22 @@
|
|
1
|
-
|
2
|
-
require 'spec/rake/spectask'
|
3
|
-
Spec::Rake::SpecTask.new {|t| t.spec_opts = ['--color']}
|
1
|
+
require 'bundler/gem_tasks'
|
4
2
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
Jeweler::Tasks.new do |gem|
|
9
|
-
gem.name = project_name
|
10
|
-
gem.summary = "Merge 2 ActiveRecords, preserving associations and attributes"
|
11
|
-
gem.email = "grosser.michael@gmail.com"
|
12
|
-
gem.homepage = "http://github.com/grosser/#{project_name}"
|
13
|
-
gem.authors = ["Michael Grosser"]
|
14
|
-
gem.add_dependency ['activerecord']
|
15
|
-
end
|
3
|
+
task :default do
|
4
|
+
sh "rspec spec/"
|
5
|
+
end
|
16
6
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
7
|
+
# extracted from https://github.com/grosser/project_template
|
8
|
+
rule /^version:bump:.*/ do |t|
|
9
|
+
sh "git status | grep 'nothing to commit'" # ensure we are not dirty
|
10
|
+
index = ['major', 'minor','patch'].index(t.name.split(':').last)
|
11
|
+
file = 'lib/ar_merge/version.rb'
|
12
|
+
|
13
|
+
version_file = File.read(file)
|
14
|
+
old_version, *version_parts = version_file.match(/(\d+)\.(\d+)\.(\d+)/).to_a
|
15
|
+
version_parts[index] = version_parts[index].to_i + 1
|
16
|
+
version_parts[2] = 0 if index < 2 # remove patch for minor
|
17
|
+
version_parts[1] = 0 if index < 1 # remove minor for major
|
18
|
+
new_version = version_parts * '.'
|
19
|
+
File.open(file,'w'){|f| f.write(version_file.sub(old_version, new_version)) }
|
20
|
+
|
21
|
+
sh "bundle && git add #{file} Gemfile.lock && git commit -m 'bump version to #{new_version}'"
|
22
|
+
end
|
@@ -10,11 +10,11 @@ INSTALL
|
|
10
10
|
|
11
11
|
Rails plugin
|
12
12
|
|
13
|
-
|
13
|
+
rails plugin install git://github.com/grosser/ar_merge.git
|
14
14
|
|
15
15
|
OR Gem
|
16
16
|
|
17
|
-
|
17
|
+
gem install ar_merge
|
18
18
|
|
19
19
|
|
20
20
|
USAGE
|
@@ -38,6 +38,6 @@ Merge duplicates
|
|
38
38
|
|
39
39
|
AUTHOR
|
40
40
|
======
|
41
|
-
[Michael Grosser](
|
42
|
-
|
43
|
-
|
41
|
+
[Michael Grosser](grosser.it)</br>
|
42
|
+
michael@grosser.it</br>
|
43
|
+
License: MIT
|
data/ar_merge.gemspec
CHANGED
@@ -1,52 +1,13 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
#
|
4
|
-
# -*- encoding: utf-8 -*-
|
1
|
+
$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
|
2
|
+
name = "ar_merge"
|
3
|
+
require "#{name}/version"
|
5
4
|
|
6
|
-
Gem::Specification.new do |s|
|
7
|
-
s.
|
8
|
-
s.version = "0.1.3"
|
9
|
-
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
5
|
+
Gem::Specification.new name, ARMerge::VERSION do |s|
|
6
|
+
s.summary = "Merge 2 ActiveRecords, preserving associations and attributes"
|
11
7
|
s.authors = ["Michael Grosser"]
|
12
|
-
s.
|
13
|
-
s.
|
14
|
-
s.
|
15
|
-
|
16
|
-
|
17
|
-
s.files = [
|
18
|
-
"README.markdown",
|
19
|
-
"Rakefile",
|
20
|
-
"VERSION",
|
21
|
-
"ar_merge.gemspec",
|
22
|
-
"init.rb",
|
23
|
-
"lib/ar_merge.rb",
|
24
|
-
"spec/ar_merge_spec.rb",
|
25
|
-
"spec/setup_test_model.rb",
|
26
|
-
"spec/spec_helper.rb"
|
27
|
-
]
|
28
|
-
s.homepage = %q{http://github.com/grosser/ar_merge}
|
29
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
30
|
-
s.require_paths = ["lib"]
|
31
|
-
s.rubygems_version = %q{1.3.5}
|
32
|
-
s.summary = %q{Merge 2 ActiveRecords, preserving associations and attributes}
|
33
|
-
s.test_files = [
|
34
|
-
"spec/spec_helper.rb",
|
35
|
-
"spec/ar_merge_spec.rb",
|
36
|
-
"spec/setup_test_model.rb"
|
37
|
-
]
|
38
|
-
|
39
|
-
if s.respond_to? :specification_version then
|
40
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
41
|
-
s.specification_version = 3
|
42
|
-
|
43
|
-
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
44
|
-
s.add_runtime_dependency(%q<activerecord>, [">= 0"])
|
45
|
-
else
|
46
|
-
s.add_dependency(%q<activerecord>, [">= 0"])
|
47
|
-
end
|
48
|
-
else
|
49
|
-
s.add_dependency(%q<activerecord>, [">= 0"])
|
50
|
-
end
|
8
|
+
s.email = "michael@grosser.it"
|
9
|
+
s.homepage = "http://github.com/grosser/#{name}"
|
10
|
+
s.files = `git ls-files`.split("\n")
|
11
|
+
s.license = "MIT"
|
12
|
+
s.add_runtime_dependency "activerecord"
|
51
13
|
end
|
52
|
-
|
data/lib/ar_merge.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
|
+
require 'ar_merge/version'
|
1
2
|
require 'active_record'
|
2
3
|
|
3
4
|
module ARMerge
|
4
|
-
VERSION = File.read( File.join(File.dirname(__FILE__),'..','VERSION') ).strip
|
5
|
-
|
6
5
|
def self.included(base)
|
7
6
|
base.extend ClassMethods
|
8
7
|
base.send(:include, InstanceMethods)
|
@@ -21,7 +20,7 @@ module ARMerge
|
|
21
20
|
|
22
21
|
#update counters, this is very basic/hacky/not secure for customized counters...
|
23
22
|
counter = "#{association_name}_count"
|
24
|
-
next unless other.respond_to?(counter)
|
23
|
+
next unless other.respond_to?(counter) and respond_to?("#{counter}=")
|
25
24
|
self.class.update_counters(id, counter => other.send(counter))
|
26
25
|
end
|
27
26
|
|
@@ -55,4 +54,4 @@ module ARMerge
|
|
55
54
|
end
|
56
55
|
end
|
57
56
|
|
58
|
-
ActiveRecord::Base.send(:include, ARMerge)
|
57
|
+
ActiveRecord::Base.send(:include, ARMerge)
|
data/spec/ar_merge_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require "
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe ARMerge do
|
4
4
|
describe :merge! do
|
@@ -40,7 +40,7 @@ describe ARMerge do
|
|
40
40
|
@user.movies.size.should == Movie.count
|
41
41
|
end
|
42
42
|
|
43
|
-
it "overtakes
|
43
|
+
it "overtakes associated objects" do
|
44
44
|
@u2.merge!(@user,:associations=>[:movies])
|
45
45
|
@u2.reload.should have(Movie.count).movies
|
46
46
|
end
|
@@ -99,4 +99,4 @@ describe ARMerge do
|
|
99
99
|
it "has a VERSION" do
|
100
100
|
ARMerge::VERSION.should =~ /^\d+\.\d+\.\d+$/
|
101
101
|
end
|
102
|
-
end
|
102
|
+
end
|
data/spec/setup_test_model.rb
CHANGED
@@ -29,6 +29,9 @@ end
|
|
29
29
|
# create models
|
30
30
|
class User < ActiveRecord::Base
|
31
31
|
has_many :movies
|
32
|
+
def movies_count
|
33
|
+
movies.count
|
34
|
+
end
|
32
35
|
end
|
33
36
|
|
34
37
|
class CountingUser < ActiveRecord::Base
|
@@ -38,4 +41,4 @@ end
|
|
38
41
|
class Movie < ActiveRecord::Base
|
39
42
|
belongs_to :user
|
40
43
|
belongs_to :counting_user, :counter_cache => true
|
41
|
-
end
|
44
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,74 +1,78 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: ar_merge
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
|
-
authors:
|
7
|
+
authors:
|
7
8
|
- Michael Grosser
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
dependencies:
|
15
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-05-14 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
16
15
|
name: activerecord
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
17
22
|
type: :runtime
|
18
|
-
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
25
30
|
description:
|
26
|
-
email:
|
31
|
+
email: michael@grosser.it
|
27
32
|
executables: []
|
28
|
-
|
29
33
|
extensions: []
|
30
|
-
|
31
|
-
|
32
|
-
-
|
33
|
-
|
34
|
-
- README.markdown
|
34
|
+
extra_rdoc_files: []
|
35
|
+
files:
|
36
|
+
- Gemfile
|
37
|
+
- Gemfile.lock
|
35
38
|
- Rakefile
|
36
|
-
-
|
39
|
+
- Readme.md
|
37
40
|
- ar_merge.gemspec
|
38
41
|
- init.rb
|
39
42
|
- lib/ar_merge.rb
|
43
|
+
- lib/ar_merge/version.rb
|
40
44
|
- spec/ar_merge_spec.rb
|
41
45
|
- spec/setup_test_model.rb
|
42
46
|
- spec/spec_helper.rb
|
43
|
-
has_rdoc: true
|
44
47
|
homepage: http://github.com/grosser/ar_merge
|
45
|
-
licenses:
|
46
|
-
|
48
|
+
licenses:
|
49
|
+
- MIT
|
47
50
|
post_install_message:
|
48
|
-
rdoc_options:
|
49
|
-
|
50
|
-
require_paths:
|
51
|
+
rdoc_options: []
|
52
|
+
require_paths:
|
51
53
|
- lib
|
52
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ! '>='
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
segments:
|
61
|
+
- 0
|
62
|
+
hash: 3854198524710893758
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
segments:
|
70
|
+
- 0
|
71
|
+
hash: 3854198524710893758
|
64
72
|
requirements: []
|
65
|
-
|
66
73
|
rubyforge_project:
|
67
|
-
rubygems_version: 1.
|
74
|
+
rubygems_version: 1.8.24
|
68
75
|
signing_key:
|
69
76
|
specification_version: 3
|
70
77
|
summary: Merge 2 ActiveRecords, preserving associations and attributes
|
71
|
-
test_files:
|
72
|
-
- spec/spec_helper.rb
|
73
|
-
- spec/ar_merge_spec.rb
|
74
|
-
- spec/setup_test_model.rb
|
78
|
+
test_files: []
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.1.3
|