fabrication 2.3.0 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,11 +1,25 @@
1
1
  class Fabrication::Generator::Sequel < Fabrication::Generator::Base
2
2
 
3
+ def initialize(klass)
4
+ super
5
+ __klass.plugin :instance_hooks unless __klass.new.respond_to? :after_save_hook
6
+ end
7
+
3
8
  def self.supports?(klass)
4
9
  defined?(Sequel) && klass.ancestors.include?(Sequel::Model)
5
10
  end
6
11
 
7
12
  def set_attributes
8
- __instance.set_fields(__attributes, __attributes.keys)
13
+ __attributes.each do |key, value|
14
+ if (reflection = __klass.association_reflections[key]) && value.is_a?(Array)
15
+ __instance.associations[key] = value
16
+ __instance.after_save_hook do
17
+ value.each { |o| __instance.send(reflection.add_method, o) }
18
+ end
19
+ else
20
+ __instance.send("#{key}=", value)
21
+ end
22
+ end
9
23
  end
10
24
 
11
25
  def persist
@@ -1,3 +1,3 @@
1
1
  module Fabrication
2
- VERSION = '2.3.0'
2
+ VERSION = '2.4.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fabrication
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-05 00:00:00.000000000 Z
12
+ date: 2012-10-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord