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 CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{anaf_habtm}
8
- s.version = "0.0.92"
8
+ s.version = "0.0.93"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Tyler Gannon"]
@@ -24,20 +24,23 @@ module AnafHabtm
24
24
  _scopes.join(".")
25
25
  end
26
26
 
27
- def anaf_habtm(association, opts={})
28
- raise "Must specify :find " unless options.has_key?(:find)
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 = make_scope_string(association, find_opts[:find])
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.extend(AnafHabtm::HashExtension)
39
- obj_attr = obj_attr.copy_without_destroy
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: 167
4
+ hash: 165
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 92
10
- version: 0.0.92
9
+ - 93
10
+ version: 0.0.93
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tyler Gannon