fabrication 2.7.1 → 2.7.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0d0a893a4b3d57bcfb26ab42020cc3150f716438
4
- data.tar.gz: 8b7c2f8933feb8ab5de7bc35c5eb7808ca2f4b1c
3
+ metadata.gz: 19952424220acd0d916eafbecf996fecc9870bd6
4
+ data.tar.gz: 443657b59d5cabc84f349a2063882304cb0b7d74
5
5
  SHA512:
6
- metadata.gz: 6348e9098f88d32c05351ad60832764592fa79d18a129735490914b41b37658438c5bafe9ba7ae9be6522c3faeec256e32673ca121686fc168f1023c7f1f5474
7
- data.tar.gz: 237b5061848736772ab368fbb98e7daa6780a1de425c65736b2572c99e3bc687ffe0493a8b8db40c0d5e6964486e8d6249879ac4c6506d670fababf92536d1b2
6
+ metadata.gz: fe4bf4524f3c8a7cf1d0a331e03a09a26e54cc77198ad0ea2e0b87d57a95da9915288c0f6f7bd209f7beffea8ce75b0549cd058785989633ec37543865751e2f
7
+ data.tar.gz: efd348378470208dd2b23539e97210024b34a16ceb3bba0c5584340adb136aeddb0353014d1633b8e59cae3ae9ead87aa3e049ef62471adb2fa9692da00f65de
@@ -31,7 +31,7 @@ module Fabrication
31
31
  end
32
32
 
33
33
  def self.clear_definitions
34
- @schematics = nil
34
+ @manager = nil
35
35
  Sequencer.sequences.clear
36
36
  end
37
37
 
@@ -39,13 +39,18 @@ module Fabrication
39
39
  Fabrication::Config.configure(&block)
40
40
  end
41
41
 
42
+ def self.manager
43
+ @manager ||= Fabrication::Schematic::Manager.new
44
+ end
45
+
42
46
  def self.schematics
43
- @schematics ||= Fabrication::Schematic::Manager.new
47
+ puts "DEPRECATION WARNING: Fabrication.schematics has been replaced by Fabrication.manager"
48
+ manager
44
49
  end
45
50
  end
46
51
 
47
52
  def Fabricator(name, options={}, &block)
48
- Fabrication.schematics.register(name, options, &block)
53
+ Fabrication.manager.register(name, options, &block)
49
54
  end
50
55
 
51
56
  def Fabricate(name, overrides={}, &block)
@@ -54,7 +54,7 @@ module Fabrication
54
54
  end
55
55
 
56
56
  def schematic
57
- Fabrication.schematics[@fabricator].tap do |schematic|
57
+ Fabrication.manager[@fabricator].tap do |schematic|
58
58
  raise Fabrication::UnknownFabricatorError, "No Fabricator defined for '#{@model}'" unless schematic
59
59
  end
60
60
  end
@@ -20,12 +20,12 @@ class Fabrication::Fabricator
20
20
  def self.fail_if_initializing(name)
21
21
  raise Fabrication::MisplacedFabricateError.new(
22
22
  "You tried to fabricate `#{name}` while Fabricators were still loading. Check your fabricator files and make sure you didn't accidentally type `Fabricate` instead of `Fabricator` in there somewhere."
23
- ) if Fabrication.schematics.initializing?
23
+ ) if Fabrication.manager.initializing?
24
24
  end
25
25
 
26
26
  def self.schematic(name)
27
- Fabrication::Support.find_definitions if Fabrication.schematics.empty?
28
- Fabrication.schematics[name].tap do |schematic|
27
+ Fabrication::Support.find_definitions if Fabrication.manager.empty?
28
+ Fabrication.manager[name].tap do |schematic|
29
29
  raise Fabrication::UnknownFabricatorError, "No Fabricator defined for '#{name}'" unless schematic
30
30
  end
31
31
  end
@@ -4,14 +4,22 @@ class Fabrication::Generator::ActiveRecord < Fabrication::Generator::Base
4
4
  defined?(ActiveRecord) && klass.ancestors.include?(ActiveRecord::Base)
5
5
  end
6
6
 
7
- private
7
+ def build_instance
8
+ if self.class.without_protection?
9
+ self._instance = _klass.new(_attributes, without_protection: true)
10
+ else
11
+ self._instance = _klass.new(_attributes)
12
+ end
13
+ end
8
14
 
9
- def validate_instance
10
- __instance.valid?
15
+ protected
16
+
17
+ def self.without_protection?
18
+ Gem::Version.new(ActiveRecord::VERSION::STRING).between?(Gem::Version.new('3.1.0'), Gem::Version.new('3.9'))
11
19
  end
12
20
 
13
- def build_instance
14
- self.__instance = __klass.new(__attributes, without_protection: true)
21
+ def validate_instance
22
+ _instance.valid?
15
23
  end
16
24
 
17
25
  end
@@ -1,6 +1,6 @@
1
1
  class Fabrication::Generator::Base
2
2
 
3
- def self.supports?(__klass); true end
3
+ def self.supports?(_klass); true end
4
4
 
5
5
  def build(attributes=[], callbacks={})
6
6
  process_attributes(attributes)
@@ -13,7 +13,7 @@ class Fabrication::Generator::Base
13
13
  build_instance
14
14
  end
15
15
  execute_callbacks(callbacks[:after_build])
16
- __instance
16
+ _instance
17
17
  end
18
18
 
19
19
  def create(attributes=[], callbacks=[])
@@ -26,17 +26,17 @@ class Fabrication::Generator::Base
26
26
  persist
27
27
  execute_callbacks(callbacks[:after_create])
28
28
  execute_callbacks(callbacks[:after_save])
29
- __instance
29
+ _instance
30
30
  end
31
31
 
32
32
  def execute_callbacks(callbacks)
33
- callbacks.each { |callback| __instance.instance_exec(__instance, __transient_attributes, &callback) } if callbacks
33
+ callbacks.each { |callback| _instance.instance_exec(_instance, _transient_attributes, &callback) } if callbacks
34
34
  end
35
35
 
36
36
  def to_hash(attributes=[], callbacks=[])
37
37
  process_attributes(attributes)
38
38
  Fabrication::Support.hash_class.new.tap do |hash|
39
- __attributes.map do |name, value|
39
+ _attributes.map do |name, value|
40
40
  if value && value.respond_to?(:id)
41
41
  hash["#{name}_id"] = value.id
42
42
  else
@@ -47,57 +47,57 @@ class Fabrication::Generator::Base
47
47
  end
48
48
 
49
49
  def build_instance_with_constructor_override(callback)
50
- self.__instance = instance_eval &callback
50
+ self._instance = instance_eval &callback
51
51
  set_attributes
52
52
  end
53
53
 
54
54
  def build_instance_with_init_callback(callback)
55
- self.__instance = __klass.new(*callback.call)
55
+ self._instance = _klass.new(*callback.call)
56
56
  set_attributes
57
57
  end
58
58
 
59
59
  def build_instance
60
- self.__instance = __klass.new
60
+ self._instance = _klass.new
61
61
  set_attributes
62
62
  end
63
63
 
64
64
  def set_attributes
65
- __attributes.each do |k,v|
66
- __instance.send("#{k}=", v)
65
+ _attributes.each do |k,v|
66
+ _instance.send("#{k}=", v)
67
67
  end
68
68
  end
69
69
 
70
70
  def initialize(klass)
71
- self.__klass = klass
71
+ self._klass = klass
72
72
  end
73
73
 
74
74
  def method_missing(method_name, *args, &block)
75
- __attributes[method_name] || super
75
+ _attributes[method_name] || super
76
76
  end
77
77
 
78
78
  def validate_instance; end
79
79
 
80
80
  protected
81
81
 
82
- attr_accessor :__klass, :__instance, :__transient_attributes
82
+ attr_accessor :_klass, :_instance, :_transient_attributes
83
83
 
84
- def __attributes
85
- @__attributes ||= {}
84
+ def _attributes
85
+ @_attributes ||= {}
86
86
  end
87
87
 
88
88
  def persist
89
- __instance.save! if __instance.respond_to?(:save!)
89
+ _instance.save! if _instance.respond_to?(:save!)
90
90
  end
91
91
 
92
92
  def post_initialize; end
93
93
 
94
94
  def process_attributes(attributes)
95
- self.__transient_attributes = Hash.new
95
+ self._transient_attributes = Hash.new
96
96
  attributes.each do |attribute|
97
- __attributes[attribute.name] = attribute.processed_value(__attributes)
98
- __transient_attributes[attribute.name] = __attributes[attribute.name] if attribute.transient?
97
+ _attributes[attribute.name] = attribute.processed_value(_attributes)
98
+ _transient_attributes[attribute.name] = _attributes[attribute.name] if attribute.transient?
99
99
  end
100
- __attributes.reject! { |k| __transient_attributes.keys.include?(k) }
100
+ _attributes.reject! { |k| _transient_attributes.keys.include?(k) }
101
101
  end
102
102
 
103
103
  end
@@ -5,17 +5,17 @@ class Fabrication::Generator::DataMapper < Fabrication::Generator::Base
5
5
  end
6
6
 
7
7
  def build_instance
8
- self.__instance = __klass.new(__attributes)
8
+ self._instance = _klass.new(_attributes)
9
9
  end
10
10
 
11
11
  def validate_instance
12
- __instance.valid?
12
+ _instance.valid?
13
13
  end
14
14
 
15
15
  protected
16
16
 
17
17
  def persist
18
- __instance.save
18
+ _instance.save
19
19
  end
20
20
 
21
21
  end
@@ -5,11 +5,11 @@ class Fabrication::Generator::Keymaker < Fabrication::Generator::Base
5
5
  end
6
6
 
7
7
  def persist
8
- __instance.save
8
+ _instance.save
9
9
  end
10
10
 
11
11
  def validate_instance
12
- __instance.valid?
12
+ _instance.valid?
13
13
  end
14
14
 
15
15
  end
@@ -6,14 +6,14 @@ class Fabrication::Generator::Mongoid < Fabrication::Generator::Base
6
6
 
7
7
  def build_instance
8
8
  if Gem::Version.new(Mongoid::VERSION).between?(Gem::Version.new('2.3.0'), Gem::Version.new('3.9'))
9
- self.__instance = __klass.new(__attributes, without_protection: true)
9
+ self._instance = _klass.new(_attributes, without_protection: true)
10
10
  else
11
- self.__instance = __klass.new(__attributes)
11
+ self._instance = _klass.new(_attributes)
12
12
  end
13
13
  end
14
14
 
15
15
  def validate_instance
16
- __instance.valid?
16
+ _instance.valid?
17
17
  end
18
18
 
19
19
  end
@@ -10,30 +10,30 @@ class Fabrication::Generator::Sequel < Fabrication::Generator::Base
10
10
  end
11
11
 
12
12
  def set_attributes
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) }
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
18
  end
19
19
  else
20
- __instance.send("#{key}=", value)
20
+ _instance.send("#{key}=", value)
21
21
  end
22
22
  end
23
23
  end
24
24
 
25
25
  def persist
26
- __instance.save
26
+ _instance.save
27
27
  end
28
28
 
29
29
  def validate_instance
30
- __instance.valid?
30
+ _instance.valid?
31
31
  end
32
32
 
33
33
  private
34
34
 
35
35
  def load_instance_hooks
36
- klass = __klass.respond_to?(:cti_base_model) ? __klass.cti_base_model : __klass
36
+ klass = _klass.respond_to?(:cti_base_model) ? _klass.cti_base_model : _klass
37
37
  klass.plugin :instance_hooks unless klass.new.respond_to? :after_save_hook
38
38
  end
39
39
 
@@ -1,7 +1,6 @@
1
1
  class Fabrication::Schematic::Definition
2
2
 
3
3
  GENERATORS = [
4
- Fabrication::Generator::ActiveRecord4,
5
4
  Fabrication::Generator::ActiveRecord,
6
5
  Fabrication::Generator::DataMapper,
7
6
  Fabrication::Generator::Sequel,
@@ -49,16 +48,16 @@ class Fabrication::Schematic::Definition
49
48
  end
50
49
 
51
50
  def build(overrides={}, &block)
52
- Fabrication.schematics.build_stack << self
51
+ Fabrication.manager.build_stack << self
53
52
  merge(overrides, &block).instance_eval do
54
53
  generator.new(klass).build(attributes, callbacks)
55
54
  end
56
55
  ensure
57
- Fabrication.schematics.build_stack.pop
56
+ Fabrication.manager.build_stack.pop
58
57
  end
59
58
 
60
59
  def fabricate(overrides={}, &block)
61
- if Fabrication.schematics.build_stack.empty?
60
+ if Fabrication.manager.build_stack.empty?
62
61
  merge(overrides, &block).instance_eval do
63
62
  generator.new(klass).create(attributes, callbacks)
64
63
  end
@@ -3,7 +3,7 @@ class Fabrication::Support
3
3
  class << self
4
4
 
5
5
  def fabricatable?(name)
6
- Fabrication.schematics[name] || class_for(name)
6
+ Fabrication.manager[name] || class_for(name)
7
7
  end
8
8
 
9
9
  def class_for(class_or_to_s)
@@ -27,13 +27,13 @@ class Fabrication::Support
27
27
  end
28
28
 
29
29
  def find_definitions
30
- Fabrication.schematics.preinitialize
30
+ Fabrication.manager.preinitialize
31
31
  Fabrication::Config.fabricator_dir.each do |folder|
32
32
  Dir.glob(File.join(Fabrication::Config.path_prefix, folder, '**', '*.rb')).sort.each do |file|
33
33
  load file
34
34
  end
35
35
  end
36
- Fabrication.schematics.freeze
36
+ Fabrication.manager.freeze
37
37
  end
38
38
 
39
39
  def hash_class
@@ -3,7 +3,7 @@ class Fabrication::Transform
3
3
  class << self
4
4
 
5
5
  def apply_to(schematic, attributes_hash)
6
- Fabrication::Support.find_definitions if Fabrication.schematics.empty?
6
+ Fabrication::Support.find_definitions if Fabrication.manager.empty?
7
7
  attributes_hash.inject({}) {|h,(k,v)| h.update(k => apply_transform(schematic, k, v)) }
8
8
  end
9
9
 
@@ -1,3 +1,3 @@
1
1
  module Fabrication
2
- VERSION = '2.7.1'
2
+ VERSION = '2.7.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fabrication
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.7.1
4
+ version: 2.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Elliott
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-21 00:00:00.000000000 Z
11
+ date: 2013-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -236,7 +236,6 @@ files:
236
236
  - lib/fabrication/errors/unknown_fabricator_error.rb
237
237
  - lib/fabrication/fabricator.rb
238
238
  - lib/fabrication/generator/active_record.rb
239
- - lib/fabrication/generator/active_record_4.rb
240
239
  - lib/fabrication/generator/base.rb
241
240
  - lib/fabrication/generator/data_mapper.rb
242
241
  - lib/fabrication/generator/keymaker.rb
@@ -1,17 +0,0 @@
1
- class Fabrication::Generator::ActiveRecord4 < Fabrication::Generator::ActiveRecord
2
-
3
- def self.supports?(klass)
4
- super && active_record_4?
5
- end
6
-
7
- def build_instance
8
- self.__instance = __klass.new(__attributes)
9
- end
10
-
11
- private
12
-
13
- def self.active_record_4?
14
- ActiveRecord::VERSION::MAJOR == 4
15
- end
16
-
17
- end