fixjour 0.1.7 → 0.2.0

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.
Files changed (2) hide show
  1. data/lib/fixjour/definitions.rb +8 -7
  2. metadata +1 -1
@@ -31,19 +31,20 @@ module Fixjour
31
31
  end
32
32
  }
33
33
 
34
- record.class.reflect_on_all_associations(:has_one).each(&transfer_singular_ids)
35
- record.class.reflect_on_all_associations(:belongs_to).each(&transfer_singular_ids)
36
-
37
34
  transfer_plural_ids = proc { |reflection|
38
- if associated = record.send(reflection.name)
35
+ associated = record.send(reflection.name)
36
+ if associated.length > 0
39
37
  associated.each { |rec| rec.new_record? && rec.save! }
40
- key = reflection.options[:foreign_key] || reflection.name.to_s + '_id'
41
- valid_attributes[key.to_s + 's'] = associated.map(&:id)
38
+ key = (reflection.options[:foreign_key] || reflection.name).to_s
39
+ key.gsub!(/_ids?$/, '')
40
+ valid_attributes[key.singularize + '_ids'] = associated.map(&:id)
42
41
  valid_attributes.delete(reflection.name)
43
42
  end
44
43
  }
45
44
 
46
- record.class.reflect_on_all_associations(:has_many).each(&transfer_plural_ids)
45
+ builder.klass.reflect_on_all_associations(:has_one).each(&transfer_singular_ids)
46
+ builder.klass.reflect_on_all_associations(:belongs_to).each(&transfer_singular_ids)
47
+ builder.klass.reflect_on_all_associations(:has_many).each(&transfer_plural_ids)
47
48
 
48
49
  valid_attributes.stringify_keys!
49
50
  valid_attributes.make_indifferent!
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fixjour
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pat Nakajima