sequel_bulk_attributes 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/lib/sequel_bulk_attributes.rb +11 -4
- data/sequel_bulk_attributes.gemspec +2 -2
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
@@ -9,15 +9,22 @@ module Sequel
|
|
9
9
|
model.associations.each do |association|
|
10
10
|
association = model.association_reflection(association)
|
11
11
|
next unless [:one_to_many].include?(association[:type])
|
12
|
+
|
12
13
|
model.class_eval do
|
13
14
|
define_method("#{association[:name]}=") do |list|
|
14
|
-
|
15
|
+
cur = send(association[:name])
|
16
|
+
instance_variable_set("@_#{association[:name]}_add", list.reject{ |v| cur.detect{ |v1| v.pk == v1.pk } })
|
17
|
+
instance_variable_set("@_#{association[:name]}_remove", cur.reject{ |v| list.detect{ |v1| v.pk == v1.pk } })
|
18
|
+
cur.replace(list)
|
19
|
+
|
15
20
|
after_save_hook do
|
16
21
|
singular_name = association[:name].to_s.singularize
|
17
|
-
|
18
|
-
|
22
|
+
|
23
|
+
instance_variable_get("@_#{association[:name]}_remove").each do |record|
|
24
|
+
send("remove_#{singular_name}", record)
|
19
25
|
end
|
20
|
-
|
26
|
+
|
27
|
+
instance_variable_get("@_#{association[:name]}_add").each do |record|
|
21
28
|
send("add_#{singular_name}", record)
|
22
29
|
end
|
23
30
|
end
|
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{sequel_bulk_attributes}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.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 = ["Corin Langosch"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-09-17}
|
13
13
|
s.description = %q{Sequel plugin which add mass assign ability for one_to_many associations for model.}
|
14
14
|
s.email = %q{info@netskin.com}
|
15
15
|
s.extra_rdoc_files = [
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 2
|
9
|
+
version: 0.0.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Corin Langosch
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-09-17 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|