anaf_habtm 0.0.92 → 0.0.93
Sign up to get free protection for your applications and to get access to all the features.
- data/anaf_habtm.gemspec +1 -1
- data/lib/anaf_habtm/anaf_active_record.rb +9 -6
- metadata +3 -3
data/anaf_habtm.gemspec
CHANGED
@@ -24,20 +24,23 @@ module AnafHabtm
|
|
24
24
|
_scopes.join(".")
|
25
25
|
end
|
26
26
|
|
27
|
-
def anaf_habtm(association,
|
28
|
-
|
27
|
+
def anaf_habtm(association, options={})
|
28
|
+
ar_opts = options[:ar_options] ||= {}
|
29
|
+
class_eval do
|
30
|
+
has_and_belongs_to_many association.to_sym, ar_opts
|
31
|
+
end
|
32
|
+
find_line = "obj = obj ||= #{klass}.#{make_scope_string(association, find_opts[:find])}.first" if options.has_key?(:find)
|
29
33
|
klass = association.to_s.singularize.camelize
|
30
34
|
association = association.to_s.underscore.tableize
|
31
|
-
scope_string =
|
35
|
+
scope_string =
|
32
36
|
class_eval <<END
|
33
37
|
def #{association}_attributes=(attr_hash)
|
34
38
|
obj_coll = []
|
35
39
|
attr_hash.each_value do |obj_attr|
|
36
40
|
next if obj_attr["_destroy"] == "1"
|
37
41
|
obj = #{klass}.find(obj_attr["id"]) if obj_attr.has_key?("id")
|
38
|
-
obj_attr.
|
39
|
-
|
40
|
-
obj = #{klass}.#{scope_string}.first unless obj
|
42
|
+
obj_attr = obj_attr.reject_keys ["id", "_destroy"]
|
43
|
+
#{find_line}
|
41
44
|
if obj && obj.update_attributes(obj_attr)
|
42
45
|
obj_coll << obj
|
43
46
|
elsif (obj = #{klass}.new(obj_attributes)) && obj.save
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: anaf_habtm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 165
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 93
|
10
|
+
version: 0.0.93
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Tyler Gannon
|