deferred_associations 0.5.5 → 0.5.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/CHANGELOG +5 -0
- data/Rakefile +27 -27
- data/Readme.markdown +84 -84
- data/deferred_associations.gemspec +61 -61
- data/init.rb +1 -1
- data/lib/has_and_belongs_to_many_with_deferred_save.rb +142 -142
- data/lib/has_many_with_deferred_save.rb +3 -3
- data/spec/db/database.yml +21 -21
- data/spec/db/schema.rb +40 -40
- data/spec/has_and_belongs_to_many_with_deferred_save_spec.rb +244 -236
- data/spec/models/door.rb +3 -3
- data/spec/models/person.rb +15 -15
- data/spec/models/room.rb +51 -51
- data/spec/spec_helper.rb +46 -46
- metadata +3 -9
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
YTc4NmE0YTU4OWY2NDIzOTRkOGE4OTk1YjU4OGNkZWM4Y2EzNTc0Mg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
N2MwNTZhOTE3MWM2MTQzYmIyZWRmMDRkMjM0OTFmMjFjOGJlZmRiMQ==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MGI0MjliNWFmNWVkN2E0MjJhZTUzNjRjNjdkNGYzOTY4NGMwNGYyYjdjYmUx
|
10
|
+
ZTAzY2Q1MDlhODZhMGJhOGExYTE3ODNmOGIwMGE5ZGM0ZGU2NjE1MmNhZDhh
|
11
|
+
ODJmYzE0NjkzMjNmNGU3NTFjNmU0ZmI4YzFlMWEwZWZiMTFhNjE=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YjUyZGExNGUwN2NjYTgwNmM4NjE3NjViZmMyMGVlYjA2ODFmNjM1MjUzNzM3
|
14
|
+
ZjY4YWI4YjJmY2I3MmY3OWUxN2U1NmQxMWI0MGUzZDRmYjMwNTViMmRlYzBl
|
15
|
+
ZGE5OTA3YWVlYWYyNjk2OGNhMzMzZTU2YWNhZTFmNzNkZDM5NzE=
|
data/CHANGELOG
CHANGED
data/Rakefile
CHANGED
@@ -1,27 +1,27 @@
|
|
1
|
-
task :default do |t|
|
2
|
-
options = "--colour"
|
3
|
-
files = FileList['spec/**/*_spec.rb'].map{|f| f.sub(%r{^spec/},'') }
|
4
|
-
exit system("cd spec && spec #{options} #{files}") ? 0 : 1
|
5
|
-
end
|
6
|
-
|
7
|
-
begin
|
8
|
-
require 'jeweler'
|
9
|
-
project_name = 'deferred_associations'
|
10
|
-
Jeweler::Tasks.new do |gem|
|
11
|
-
gem.name = project_name
|
12
|
-
gem.summary = "Makes ActiveRecord defer/postpone habtm or has_many associations"
|
13
|
-
gem.description = "Makes ActiveRecord defer/postpone saving the records you add to an habtm (has_and_belongs_to_many) or has_many
|
14
|
-
association until you call model.save, allowing validation in the style of normal attributes. Additionally you
|
15
|
-
can check inside before_save filters, if the association was altered."
|
16
|
-
gem.homepage = "http://github.com/MartinKoerner/deferred_associations"
|
17
|
-
gem.email = "martin.koerner@objectfab.de"
|
18
|
-
gem.authors = ["Martin Koerner", "Tyler Rick", "Alessio Caiazza"]
|
19
|
-
gem.add_dependency('activerecord')
|
20
|
-
gem.add_development_dependency('rspec')
|
21
|
-
gem.files.exclude 'gemfiles/*', '.travis.yml'
|
22
|
-
end
|
23
|
-
|
24
|
-
Jeweler::GemcutterTasks.new
|
25
|
-
rescue LoadError
|
26
|
-
puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
27
|
-
end
|
1
|
+
task :default do |t|
|
2
|
+
options = "--colour"
|
3
|
+
files = FileList['spec/**/*_spec.rb'].map{|f| f.sub(%r{^spec/},'') }
|
4
|
+
exit system("cd spec && spec #{options} #{files}") ? 0 : 1
|
5
|
+
end
|
6
|
+
|
7
|
+
begin
|
8
|
+
require 'jeweler'
|
9
|
+
project_name = 'deferred_associations'
|
10
|
+
Jeweler::Tasks.new do |gem|
|
11
|
+
gem.name = project_name
|
12
|
+
gem.summary = "Makes ActiveRecord defer/postpone habtm or has_many associations"
|
13
|
+
gem.description = "Makes ActiveRecord defer/postpone saving the records you add to an habtm (has_and_belongs_to_many) or has_many
|
14
|
+
association until you call model.save, allowing validation in the style of normal attributes. Additionally you
|
15
|
+
can check inside before_save filters, if the association was altered."
|
16
|
+
gem.homepage = "http://github.com/MartinKoerner/deferred_associations"
|
17
|
+
gem.email = "martin.koerner@objectfab.de"
|
18
|
+
gem.authors = ["Martin Koerner", "Tyler Rick", "Alessio Caiazza"]
|
19
|
+
gem.add_dependency('activerecord')
|
20
|
+
gem.add_development_dependency('rspec')
|
21
|
+
gem.files.exclude 'gemfiles/*', '.travis.yml'
|
22
|
+
end
|
23
|
+
|
24
|
+
Jeweler::GemcutterTasks.new
|
25
|
+
rescue LoadError
|
26
|
+
puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
27
|
+
end
|
data/Readme.markdown
CHANGED
@@ -1,85 +1,85 @@
|
|
1
|
-
Make ActiveRecord defer/postpone saving the records you add to an habtm (has_and_belongs_to_many) or has_many association
|
2
|
-
until you call model.save, allowing validation in the style of normal attributes.
|
3
|
-
|
4
|
-
[![Build Status](https://secure.travis-ci.org/MartinKoerner/deferred_associations.png?branch=master)](http://travis-ci.org/MartinKoerner/deferred_associations) [![Dependency Status](https://gemnasium.com/MartinKoerner/deferred_associations.png?travis)](https://gemnasium.com/MartinKoerner/deferred_associations)
|
5
|
-
|
6
|
-
How to install
|
7
|
-
==============
|
8
|
-
|
9
|
-
gem install deferred_associations
|
10
|
-
|
11
|
-
Usage
|
12
|
-
=====
|
13
|
-
|
14
|
-
class Room < ActiveRecord::Base
|
15
|
-
has_and_belongs_to_many_with_deferred_save :people
|
16
|
-
has_many_with_deferred_save :tables
|
17
|
-
|
18
|
-
validate :usage
|
19
|
-
before_save :check_change
|
20
|
-
|
21
|
-
def usage
|
22
|
-
if people.size > 30
|
23
|
-
errors.add :people, "There are too many people in this room"
|
24
|
-
end
|
25
|
-
if tables.size > 15
|
26
|
-
errors.add :tables, "There are too many tables in this room"
|
27
|
-
end
|
28
|
-
# Neither people nor tables are saved to the database, if a validation error is added
|
29
|
-
end
|
30
|
-
|
31
|
-
def check_change
|
32
|
-
# you can check, if there were changes to the association
|
33
|
-
if people != people_without_deferred_save
|
34
|
-
self.updated_at = Time.now.utc
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
Compatibility
|
40
|
-
=============
|
41
|
-
|
42
|
-
Tested with Rails 2.3.14, 3.2.3, 3.2.14 on Ruby 1.8.7, 1.9.3 and JRuby 1.7.
|
43
|
-
|
44
|
-
Note, that Rails 3.2.14 associations are partly broken under JRuby cause of https://github.com/rails/rails/issues/11595
|
45
|
-
You'll need to upgrade activerecord-jdbc-adapter to >= 1.3.0.beta1, if you want to use this combination.
|
46
|
-
|
47
|
-
Gotchas
|
48
|
-
=======
|
49
|
-
|
50
|
-
Be aware, that the habtm association objects sometimes asks the database instead of giving you the data directly from the array. So you can get something
|
51
|
-
like
|
52
|
-
|
53
|
-
room = Room.create
|
54
|
-
room.people << Person.create
|
55
|
-
room.people.first # => nil, since the DB doesn't have the association saved yet
|
56
|
-
|
57
|
-
|
58
|
-
Also it is good to know, that the array you set to an association is stored there directly, so after setting a list, the typical association
|
59
|
-
methods are not working:
|
60
|
-
|
61
|
-
room = Room.create
|
62
|
-
room.people.klass # => Person
|
63
|
-
room.people = [Person.first]
|
64
|
-
room.people.klass # => undefined method klass for #Array:0x007fa3b9efc2c0`
|
65
|
-
|
66
|
-
Bugs
|
67
|
-
====
|
68
|
-
|
69
|
-
http://github.com/MartinKoerner/deferred_associations/issues
|
70
|
-
|
71
|
-
History
|
72
|
-
======
|
73
|
-
|
74
|
-
Most of the code for the habtm association was written by TylerRick for his gem [has_and_belongs_to_many_with_deferred_save](https://github.com/TylerRick/has_and_belongs_to_many_with_deferred_save)
|
75
|
-
Mainly, I changed two things:
|
76
|
-
|
77
|
-
* added ActiveRecord 3 compatibility
|
78
|
-
* removed singleton methods, because they interfere with caching
|
79
|
-
|
80
|
-
License
|
81
|
-
=======
|
82
|
-
|
83
|
-
This plugin is licensed under the BSD license.
|
84
|
-
|
1
|
+
Make ActiveRecord defer/postpone saving the records you add to an habtm (has_and_belongs_to_many) or has_many association
|
2
|
+
until you call model.save, allowing validation in the style of normal attributes.
|
3
|
+
|
4
|
+
[![Build Status](https://secure.travis-ci.org/MartinKoerner/deferred_associations.png?branch=master)](http://travis-ci.org/MartinKoerner/deferred_associations) [![Dependency Status](https://gemnasium.com/MartinKoerner/deferred_associations.png?travis)](https://gemnasium.com/MartinKoerner/deferred_associations)
|
5
|
+
|
6
|
+
How to install
|
7
|
+
==============
|
8
|
+
|
9
|
+
gem install deferred_associations
|
10
|
+
|
11
|
+
Usage
|
12
|
+
=====
|
13
|
+
|
14
|
+
class Room < ActiveRecord::Base
|
15
|
+
has_and_belongs_to_many_with_deferred_save :people
|
16
|
+
has_many_with_deferred_save :tables
|
17
|
+
|
18
|
+
validate :usage
|
19
|
+
before_save :check_change
|
20
|
+
|
21
|
+
def usage
|
22
|
+
if people.size > 30
|
23
|
+
errors.add :people, "There are too many people in this room"
|
24
|
+
end
|
25
|
+
if tables.size > 15
|
26
|
+
errors.add :tables, "There are too many tables in this room"
|
27
|
+
end
|
28
|
+
# Neither people nor tables are saved to the database, if a validation error is added
|
29
|
+
end
|
30
|
+
|
31
|
+
def check_change
|
32
|
+
# you can check, if there were changes to the association
|
33
|
+
if people != people_without_deferred_save
|
34
|
+
self.updated_at = Time.now.utc
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
Compatibility
|
40
|
+
=============
|
41
|
+
|
42
|
+
Tested with Rails 2.3.14, 3.2.3, 3.2.14, 4.0 and 4.1 on Ruby 1.8.7, 1.9.3 and JRuby 1.7.12
|
43
|
+
|
44
|
+
Note, that Rails 3.2.14 associations are partly broken under JRuby cause of https://github.com/rails/rails/issues/11595
|
45
|
+
You'll need to upgrade activerecord-jdbc-adapter to >= 1.3.0.beta1, if you want to use this combination.
|
46
|
+
|
47
|
+
Gotchas
|
48
|
+
=======
|
49
|
+
|
50
|
+
Be aware, that the habtm association objects sometimes asks the database instead of giving you the data directly from the array. So you can get something
|
51
|
+
like
|
52
|
+
|
53
|
+
room = Room.create
|
54
|
+
room.people << Person.create
|
55
|
+
room.people.first # => nil, since the DB doesn't have the association saved yet
|
56
|
+
|
57
|
+
|
58
|
+
Also it is good to know, that the array you set to an association is stored there directly, so after setting a list, the typical association
|
59
|
+
methods are not working:
|
60
|
+
|
61
|
+
room = Room.create
|
62
|
+
room.people.klass # => Person
|
63
|
+
room.people = [Person.first]
|
64
|
+
room.people.klass # => undefined method klass for #Array:0x007fa3b9efc2c0`
|
65
|
+
|
66
|
+
Bugs
|
67
|
+
====
|
68
|
+
|
69
|
+
http://github.com/MartinKoerner/deferred_associations/issues
|
70
|
+
|
71
|
+
History
|
72
|
+
======
|
73
|
+
|
74
|
+
Most of the code for the habtm association was written by TylerRick for his gem [has_and_belongs_to_many_with_deferred_save](https://github.com/TylerRick/has_and_belongs_to_many_with_deferred_save)
|
75
|
+
Mainly, I changed two things:
|
76
|
+
|
77
|
+
* added ActiveRecord 3 compatibility
|
78
|
+
* removed singleton methods, because they interfere with caching
|
79
|
+
|
80
|
+
License
|
81
|
+
=======
|
82
|
+
|
83
|
+
This plugin is licensed under the BSD license.
|
84
|
+
|
85
85
|
2013 (c) Martin Körner
|
@@ -1,61 +1,61 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in rakefile, and run 'rake gemspec'
|
4
|
-
# -*- encoding: utf-8 -*-
|
5
|
-
|
6
|
-
Gem::Specification.new do |s|
|
7
|
-
s.name = "deferred_associations"
|
8
|
-
s.version = "0.5.
|
9
|
-
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["Martin Koerner", "Tyler Rick", "Alessio Caiazza"]
|
12
|
-
s.date = "2013-10-25"
|
13
|
-
s.description = "Makes ActiveRecord defer/postpone saving the records you add to an habtm (has_and_belongs_to_many) or has_many\n association until you call model.save, allowing validation in the style of normal attributes. Additionally you\n can check inside before_save filters, if the association was altered."
|
14
|
-
s.email = "martin.koerner@objectfab.de"
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"CHANGELOG",
|
17
|
-
"Readme.markdown"
|
18
|
-
]
|
19
|
-
s.files = [
|
20
|
-
"CHANGELOG",
|
21
|
-
"Rakefile",
|
22
|
-
"Readme.markdown",
|
23
|
-
"VERSION",
|
24
|
-
"deferred_associations.gemspec",
|
25
|
-
"init.rb",
|
26
|
-
"lib/array_to_association_wrapper.rb",
|
27
|
-
"lib/deferred_associations.rb",
|
28
|
-
"lib/has_and_belongs_to_many_with_deferred_save.rb",
|
29
|
-
"lib/has_many_with_deferred_save.rb",
|
30
|
-
"spec/db/database.yml",
|
31
|
-
"spec/db/schema.rb",
|
32
|
-
"spec/has_and_belongs_to_many_with_deferred_save_spec.rb",
|
33
|
-
"spec/has_many_with_deferred_save_spec.rb",
|
34
|
-
"spec/models/chair.rb",
|
35
|
-
"spec/models/door.rb",
|
36
|
-
"spec/models/person.rb",
|
37
|
-
"spec/models/room.rb",
|
38
|
-
"spec/models/table.rb",
|
39
|
-
"spec/spec_helper.rb"
|
40
|
-
]
|
41
|
-
s.homepage = "http://github.com/MartinKoerner/deferred_associations"
|
42
|
-
s.require_paths = ["lib"]
|
43
|
-
s.rubygems_version = "1.8.24"
|
44
|
-
s.summary = "Makes ActiveRecord defer/postpone habtm or has_many associations"
|
45
|
-
|
46
|
-
if s.respond_to? :specification_version then
|
47
|
-
s.specification_version = 3
|
48
|
-
|
49
|
-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
50
|
-
s.add_runtime_dependency(%q<activerecord>, [">= 0"])
|
51
|
-
s.add_development_dependency(%q<rspec>, [">= 0"])
|
52
|
-
else
|
53
|
-
s.add_dependency(%q<activerecord>, [">= 0"])
|
54
|
-
s.add_dependency(%q<rspec>, [">= 0"])
|
55
|
-
end
|
56
|
-
else
|
57
|
-
s.add_dependency(%q<activerecord>, [">= 0"])
|
58
|
-
s.add_dependency(%q<rspec>, [">= 0"])
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "deferred_associations"
|
8
|
+
s.version = "0.5.6"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Martin Koerner", "Tyler Rick", "Alessio Caiazza"]
|
12
|
+
s.date = "2013-10-25"
|
13
|
+
s.description = "Makes ActiveRecord defer/postpone saving the records you add to an habtm (has_and_belongs_to_many) or has_many\n association until you call model.save, allowing validation in the style of normal attributes. Additionally you\n can check inside before_save filters, if the association was altered."
|
14
|
+
s.email = "martin.koerner@objectfab.de"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"CHANGELOG",
|
17
|
+
"Readme.markdown"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
"CHANGELOG",
|
21
|
+
"Rakefile",
|
22
|
+
"Readme.markdown",
|
23
|
+
"VERSION",
|
24
|
+
"deferred_associations.gemspec",
|
25
|
+
"init.rb",
|
26
|
+
"lib/array_to_association_wrapper.rb",
|
27
|
+
"lib/deferred_associations.rb",
|
28
|
+
"lib/has_and_belongs_to_many_with_deferred_save.rb",
|
29
|
+
"lib/has_many_with_deferred_save.rb",
|
30
|
+
"spec/db/database.yml",
|
31
|
+
"spec/db/schema.rb",
|
32
|
+
"spec/has_and_belongs_to_many_with_deferred_save_spec.rb",
|
33
|
+
"spec/has_many_with_deferred_save_spec.rb",
|
34
|
+
"spec/models/chair.rb",
|
35
|
+
"spec/models/door.rb",
|
36
|
+
"spec/models/person.rb",
|
37
|
+
"spec/models/room.rb",
|
38
|
+
"spec/models/table.rb",
|
39
|
+
"spec/spec_helper.rb"
|
40
|
+
]
|
41
|
+
s.homepage = "http://github.com/MartinKoerner/deferred_associations"
|
42
|
+
s.require_paths = ["lib"]
|
43
|
+
s.rubygems_version = "1.8.24"
|
44
|
+
s.summary = "Makes ActiveRecord defer/postpone habtm or has_many associations"
|
45
|
+
|
46
|
+
if s.respond_to? :specification_version then
|
47
|
+
s.specification_version = 3
|
48
|
+
|
49
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
50
|
+
s.add_runtime_dependency(%q<activerecord>, [">= 0"])
|
51
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
52
|
+
else
|
53
|
+
s.add_dependency(%q<activerecord>, [">= 0"])
|
54
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
55
|
+
end
|
56
|
+
else
|
57
|
+
s.add_dependency(%q<activerecord>, [">= 0"])
|
58
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
data/init.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require 'deferred_associations'
|
1
|
+
require 'deferred_associations'
|