fabrication 2.29.0 → 3.0.0.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/fabricate.rb +5 -11
- data/lib/fabrication/config.rb +10 -35
- data/lib/fabrication/cucumber/step_fabricator.rb +5 -13
- data/lib/fabrication/generator/active_record.rb +5 -5
- data/lib/fabrication/generator/base.rb +8 -16
- data/lib/fabrication/generator/mongoid.rb +3 -3
- data/lib/fabrication/generator/sequel.rb +3 -3
- data/lib/fabrication/schematic/attribute.rb +2 -2
- data/lib/fabrication/schematic/definition.rb +1 -2
- data/lib/fabrication/schematic/manager.rb +5 -7
- data/lib/fabrication/sequencer.rb +4 -17
- data/lib/fabrication/support.rb +55 -50
- data/lib/fabrication/transform.rb +16 -18
- data/lib/fabrication/version.rb +1 -1
- data/lib/fabrication.rb +8 -6
- data/lib/rails/generators/fabrication/cucumber_steps/cucumber_steps_generator.rb +1 -1
- data/lib/rails/generators/fabrication/cucumber_steps/templates/fabrication_steps.rb +1 -3
- data/lib/rails/generators/fabrication/model/model_generator.rb +1 -3
- metadata +9 -17
- data/lib/fabrication/generator/data_mapper.rb +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 20a02618a5107ba5850de6da2bd58ae428d33d8163ab3c71f9233574780998df
|
4
|
+
data.tar.gz: 33bac0b9d796da2d94adf3a8eb8940ff8766c36c9435429a03a1da0dd1efb8ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0d2aa56f7153981b3be287dde1204a1050b964e5bdba14314d7f7cda4d7af7a4960cb2670bd2c58b7615768fdea84c4dbd15da2d1db95b5b4371e86091b336d
|
7
|
+
data.tar.gz: a182aecb4c3d38e36cd0e8f282dfd575b7234427a15e7f575cdbc84ca090848f162de9becc0989cef3baaa76c986a946c467b53adb937c5011932af774735b25
|
data/lib/fabricate.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
class Fabricate
|
2
2
|
def self.times(count, name, overrides = {}, &block)
|
3
|
-
|
3
|
+
count.times.map { Fabricate(name, overrides, &block) }
|
4
4
|
end
|
5
5
|
|
6
6
|
def self.build_times(count, name, overrides = {}, &block)
|
7
|
-
|
7
|
+
count.times.map { Fabricate.build(name, overrides, &block) }
|
8
8
|
end
|
9
9
|
|
10
10
|
def self.attributes_for_times(count, name, overrides = {}, &block)
|
11
|
-
|
11
|
+
count.times.map { Fabricate.attributes_for(name, overrides, &block) }
|
12
12
|
end
|
13
13
|
|
14
14
|
def self.attributes_for(name, overrides = {}, &block)
|
@@ -24,19 +24,13 @@ class Fabricate
|
|
24
24
|
def self.build(name, overrides = {}, &block)
|
25
25
|
fail_if_initializing(name)
|
26
26
|
schematic(name).build(overrides, &block).tap do |object|
|
27
|
-
Fabrication::Config.
|
28
|
-
notifier.call(name, object)
|
29
|
-
end
|
27
|
+
Fabrication::Cucumber::Fabrications[name] = object if Fabrication::Config.register_with_steps?
|
30
28
|
end
|
31
29
|
end
|
32
30
|
|
33
31
|
def self.create(name, overrides = {}, &block)
|
34
32
|
fail_if_initializing(name)
|
35
|
-
schematic(name).fabricate(overrides, &block)
|
36
|
-
Fabrication::Config.notifiers.each do |notifier|
|
37
|
-
notifier.call(name, object)
|
38
|
-
end
|
39
|
-
end
|
33
|
+
schematic(name).fabricate(overrides, &block)
|
40
34
|
end
|
41
35
|
|
42
36
|
def self.sequence(name = Fabrication::Sequencer::DEFAULT, start = nil, &block)
|
data/lib/fabrication/config.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'logger'
|
2
|
-
|
3
1
|
module Fabrication
|
4
2
|
module Config
|
5
3
|
extend self
|
@@ -16,22 +14,14 @@ module Fabrication
|
|
16
14
|
nil
|
17
15
|
end
|
18
16
|
|
19
|
-
attr_writer :logger, :sequence_start
|
20
|
-
|
21
|
-
def logger
|
22
|
-
@logger ||= Logger.new($stdout).tap do |logger|
|
23
|
-
logger.level = Logger::WARN
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
17
|
def fabricator_path
|
28
18
|
@fabricator_path ||= ['test/fabricators', 'spec/fabricators']
|
29
19
|
end
|
30
20
|
alias fabricator_paths fabricator_path
|
31
21
|
|
32
22
|
def fabricator_dir
|
33
|
-
|
34
|
-
|
23
|
+
puts 'DEPRECATION WARNING: Fabrication::Config.fabricator_dir has been ' \
|
24
|
+
'replaced by Fabrication::Config.fabricator_path'
|
35
25
|
fabricator_path
|
36
26
|
end
|
37
27
|
|
@@ -40,11 +30,13 @@ module Fabrication
|
|
40
30
|
end
|
41
31
|
|
42
32
|
def fabricator_dir=(folders)
|
43
|
-
|
44
|
-
|
33
|
+
puts 'DEPRECATION WARNING: Fabrication::Config.fabricator_dir has been ' \
|
34
|
+
'replaced by Fabrication::Config.fabricator_path'
|
45
35
|
self.fabricator_path = folders
|
46
36
|
end
|
47
37
|
|
38
|
+
attr_writer :sequence_start, :register_with_steps
|
39
|
+
|
48
40
|
def sequence_start
|
49
41
|
@sequence_start ||= 0
|
50
42
|
end
|
@@ -58,6 +50,10 @@ module Fabrication
|
|
58
50
|
end
|
59
51
|
alias path_prefixes path_prefix
|
60
52
|
|
53
|
+
def register_with_steps?
|
54
|
+
@register_with_steps ||= nil
|
55
|
+
end
|
56
|
+
|
61
57
|
def generators
|
62
58
|
@generators ||= []
|
63
59
|
end
|
@@ -73,26 +69,5 @@ module Fabrication
|
|
73
69
|
def recursion_limit=(limit)
|
74
70
|
@recursion_limit = limit
|
75
71
|
end
|
76
|
-
|
77
|
-
def register_with_steps=(value)
|
78
|
-
Support.log_deprecation(
|
79
|
-
'Fabrication::Config.register_with_steps has been deprecated. ' \
|
80
|
-
'Please regenerate your cucumber steps with `rails g fabrication:cucumber_steps'
|
81
|
-
)
|
82
|
-
|
83
|
-
return unless value
|
84
|
-
|
85
|
-
register_notifier do |name, object|
|
86
|
-
Fabrication::Cucumber::Fabrications[name] = object
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
def notifiers
|
91
|
-
@notifiers ||= []
|
92
|
-
end
|
93
|
-
|
94
|
-
def register_notifier(&block)
|
95
|
-
notifiers.push(block)
|
96
|
-
end
|
97
72
|
end
|
98
73
|
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'singleton'
|
2
|
-
|
3
1
|
module Fabrication
|
4
2
|
module Cucumber
|
5
3
|
class StepFabricator
|
@@ -22,7 +20,7 @@ module Fabrication
|
|
22
20
|
end
|
23
21
|
|
24
22
|
def n(count, attrs = {})
|
25
|
-
|
23
|
+
count.times.map { make(attrs) }.tap { |o| remember(o) }
|
26
24
|
end
|
27
25
|
|
28
26
|
# rubocop:disable Naming/PredicateName
|
@@ -87,23 +85,17 @@ module Fabrication
|
|
87
85
|
end
|
88
86
|
end
|
89
87
|
|
90
|
-
|
91
|
-
include Singleton
|
92
|
-
|
88
|
+
module Fabrications
|
93
89
|
def self.fabrications
|
94
|
-
|
90
|
+
@fabrications ||= {}
|
95
91
|
end
|
96
92
|
|
97
93
|
def self.[](fabricator)
|
98
|
-
|
94
|
+
fabrications[fabricator.to_sym]
|
99
95
|
end
|
100
96
|
|
101
97
|
def self.[]=(fabricator, fabrication)
|
102
|
-
|
103
|
-
end
|
104
|
-
|
105
|
-
def fabrications
|
106
|
-
@fabrications ||= {}
|
98
|
+
fabrications[fabricator.to_sym] = fabrication
|
107
99
|
end
|
108
100
|
end
|
109
101
|
end
|
@@ -6,15 +6,15 @@ module Fabrication
|
|
6
6
|
# so we can't assume because we have the ActiveRecord module that we also
|
7
7
|
# have ActiveRecord::Base. Because defined? can return nil we ensure that nil
|
8
8
|
# becomes false.
|
9
|
-
|
10
|
-
klass.ancestors.include?(::ActiveRecord::Base)
|
9
|
+
defined?(::ActiveRecord) && defined?(::ActiveRecord::Base) &&
|
10
|
+
klass.ancestors.include?(::ActiveRecord::Base) || false
|
11
11
|
end
|
12
12
|
|
13
13
|
def build_instance
|
14
|
-
self._instance = if
|
15
|
-
|
14
|
+
self._instance = if _klass.respond_to?(:protected_attributes)
|
15
|
+
_klass.new(_attributes, without_protection: true)
|
16
16
|
else
|
17
|
-
|
17
|
+
_klass.new(_attributes)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Fabrication
|
2
2
|
module Generator
|
3
3
|
class Base
|
4
|
-
def self.supports?(
|
4
|
+
def self.supports?(_klass)
|
5
5
|
true
|
6
6
|
end
|
7
7
|
|
@@ -54,17 +54,17 @@ module Fabrication
|
|
54
54
|
end
|
55
55
|
|
56
56
|
def build_instance_with_constructor_override(callback)
|
57
|
-
self._instance =
|
57
|
+
self._instance = instance_eval(&callback)
|
58
58
|
set_attributes
|
59
59
|
end
|
60
60
|
|
61
61
|
def build_instance_with_init_callback(callback)
|
62
|
-
self._instance =
|
62
|
+
self._instance = _klass.new(*callback.call)
|
63
63
|
set_attributes
|
64
64
|
end
|
65
65
|
|
66
66
|
def build_instance
|
67
|
-
self._instance =
|
67
|
+
self._instance = _klass.new
|
68
68
|
set_attributes
|
69
69
|
end
|
70
70
|
|
@@ -74,8 +74,8 @@ module Fabrication
|
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
|
-
def initialize(
|
78
|
-
self.
|
77
|
+
def initialize(klass)
|
78
|
+
self._klass = klass
|
79
79
|
end
|
80
80
|
|
81
81
|
def respond_to_missing?(method_name, _include_private = false)
|
@@ -86,17 +86,9 @@ module Fabrication
|
|
86
86
|
_attributes.fetch(method_name) { super }
|
87
87
|
end
|
88
88
|
|
89
|
-
def _klass
|
90
|
-
Fabrication::Support.log_deprecation(
|
91
|
-
'The `_klass` method in fabricator definitions has been replaced by `resolved_class`'
|
92
|
-
)
|
93
|
-
|
94
|
-
resolved_class
|
95
|
-
end
|
96
|
-
|
97
89
|
protected
|
98
90
|
|
99
|
-
attr_accessor :
|
91
|
+
attr_accessor :_klass, :_instance, :_transient_attributes
|
100
92
|
|
101
93
|
def _attributes
|
102
94
|
@_attributes ||= {}
|
@@ -112,7 +104,7 @@ module Fabrication
|
|
112
104
|
_attributes[attribute.name] = attribute.processed_value(_attributes)
|
113
105
|
_transient_attributes[attribute.name] = _attributes[attribute.name] if attribute.transient?
|
114
106
|
end
|
115
|
-
_attributes.reject! { |k| _transient_attributes.
|
107
|
+
_attributes.reject! { |k| _transient_attributes.keys.include?(k) }
|
116
108
|
end
|
117
109
|
end
|
118
110
|
end
|
@@ -6,10 +6,10 @@ module Fabrication
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def build_instance
|
9
|
-
self._instance = if
|
10
|
-
|
9
|
+
self._instance = if _klass.respond_to?(:protected_attributes)
|
10
|
+
_klass.new(_attributes, without_protection: true)
|
11
11
|
else
|
12
|
-
|
12
|
+
_klass.new(_attributes)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
@@ -7,12 +7,12 @@ module Fabrication
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def self.supports?(klass)
|
10
|
-
defined?(::Sequel) &&
|
10
|
+
defined?(::Sequel) && klass.ancestors.include?(::Sequel::Model)
|
11
11
|
end
|
12
12
|
|
13
13
|
def set_attributes
|
14
14
|
_attributes.each do |key, value|
|
15
|
-
if (reflection =
|
15
|
+
if (reflection = _klass.association_reflections[key]) && value.is_a?(Array)
|
16
16
|
_instance.associations[key] = value
|
17
17
|
_instance.after_save_hook do
|
18
18
|
value.each { |o| _instance.send(reflection.add_method, o) }
|
@@ -30,7 +30,7 @@ module Fabrication
|
|
30
30
|
private
|
31
31
|
|
32
32
|
def load_instance_hooks
|
33
|
-
klass =
|
33
|
+
klass = _klass.respond_to?(:cti_base_model) ? _klass.cti_models.first : _klass
|
34
34
|
klass.plugin :instance_hooks unless klass.new.respond_to? :after_save_hook
|
35
35
|
end
|
36
36
|
end
|
@@ -3,7 +3,6 @@ module Fabrication
|
|
3
3
|
class Definition
|
4
4
|
GENERATORS = [
|
5
5
|
Fabrication::Generator::ActiveRecord,
|
6
|
-
Fabrication::Generator::DataMapper,
|
7
6
|
Fabrication::Generator::Sequel,
|
8
7
|
Fabrication::Generator::Mongoid,
|
9
8
|
Fabrication::Generator::Base
|
@@ -18,7 +17,7 @@ module Fabrication
|
|
18
17
|
end
|
19
18
|
|
20
19
|
def process_block(&block)
|
21
|
-
Fabrication::Schematic::Evaluator.new.process(self, &block) if
|
20
|
+
Fabrication::Schematic::Evaluator.new.process(self, &block) if block_given?
|
22
21
|
end
|
23
22
|
|
24
23
|
def attribute(name)
|
@@ -55,16 +55,14 @@ module Fabrication
|
|
55
55
|
def load_definitions
|
56
56
|
preinitialize
|
57
57
|
Fabrication::Config.path_prefixes.each do |prefix|
|
58
|
-
Fabrication::Config.fabricator_paths.each do |
|
59
|
-
|
60
|
-
load
|
61
|
-
else
|
62
|
-
Dir.glob(File.join(prefix.to_s, path, '**', '*.rb')).sort.each do |file|
|
63
|
-
load file
|
64
|
-
end
|
58
|
+
Fabrication::Config.fabricator_paths.each do |folder|
|
59
|
+
Dir.glob(File.join(prefix.to_s, folder, '**', '*.rb')).sort.each do |file|
|
60
|
+
load file
|
65
61
|
end
|
66
62
|
end
|
67
63
|
end
|
64
|
+
rescue StandardError => e
|
65
|
+
raise e
|
68
66
|
ensure
|
69
67
|
freeze
|
70
68
|
end
|
@@ -1,23 +1,10 @@
|
|
1
|
-
require 'singleton'
|
2
|
-
|
3
1
|
module Fabrication
|
4
2
|
class Sequencer
|
5
|
-
include Singleton
|
6
|
-
|
7
3
|
DEFAULT = :_default
|
8
4
|
|
9
5
|
def self.sequence(name = DEFAULT, start = nil, &block)
|
10
|
-
instance.sequence(name, start, &block)
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.clear
|
14
|
-
instance.sequences.clear
|
15
|
-
instance.sequence_blocks.clear
|
16
|
-
end
|
17
|
-
|
18
|
-
def sequence(name = DEFAULT, start = nil, &block)
|
19
6
|
idx = sequences[name] ||= start || Fabrication::Config.sequence_start
|
20
|
-
if
|
7
|
+
if block_given?
|
21
8
|
sequence_blocks[name] = block.to_proc
|
22
9
|
else
|
23
10
|
sequence_blocks[name] ||= ->(i) { i }
|
@@ -26,15 +13,15 @@ module Fabrication
|
|
26
13
|
end
|
27
14
|
end
|
28
15
|
|
29
|
-
def sequences
|
16
|
+
def self.sequences
|
30
17
|
@sequences ||= {}
|
31
18
|
end
|
32
19
|
|
33
|
-
def sequence_blocks
|
20
|
+
def self.sequence_blocks
|
34
21
|
@sequence_blocks ||= {}
|
35
22
|
end
|
36
23
|
|
37
|
-
def reset
|
24
|
+
def self.reset
|
38
25
|
Fabrication::Config.sequence_start = nil
|
39
26
|
@sequences = nil
|
40
27
|
@sequence_blocks = nil
|
data/lib/fabrication/support.rb
CHANGED
@@ -1,68 +1,73 @@
|
|
1
1
|
module Fabrication
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
end
|
2
|
+
class Support
|
3
|
+
class << self
|
4
|
+
def fabricatable?(name)
|
5
|
+
Fabrication.manager[name] || class_for(name)
|
6
|
+
end
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
def class_for(class_or_to_s)
|
9
|
+
class_name = variable_name_to_class_name(class_or_to_s)
|
10
|
+
constantize(class_name)
|
11
|
+
rescue NameError => e
|
12
|
+
raise Fabrication::UnfabricatableError.new(class_or_to_s, e)
|
13
|
+
end
|
12
14
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
def constantize(camel_cased_word)
|
16
|
+
names = camel_cased_word.split('::')
|
17
|
+
Object.const_get(camel_cased_word) if names.empty?
|
18
|
+
names.shift if names.size > 1 && names.first.empty?
|
19
|
+
names.inject(Object) do |constant, name|
|
20
|
+
if constant == Object
|
21
|
+
constant.const_get(name)
|
22
|
+
else
|
23
|
+
candidate = constant.const_get(name)
|
24
|
+
next candidate if constant.const_defined?(name, false)
|
25
|
+
next candidate unless Object.const_defined?(name)
|
18
26
|
|
19
|
-
|
20
|
-
|
27
|
+
constant = constant.ancestors.inject do |const, ancestor|
|
28
|
+
break const if ancestor == Object
|
29
|
+
break ancestor if ancestor.const_defined?(name, false)
|
21
30
|
|
22
|
-
|
23
|
-
|
31
|
+
const
|
32
|
+
end
|
33
|
+
constant.const_get(name, false)
|
34
|
+
end
|
35
|
+
end
|
24
36
|
end
|
25
|
-
end
|
26
37
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
def variable_name_to_class_name(name)
|
32
|
-
name_string = name.to_s
|
38
|
+
def extract_options!(args)
|
39
|
+
args.last.is_a?(::Hash) ? args.pop : {}
|
40
|
+
end
|
33
41
|
|
34
|
-
|
35
|
-
|
36
|
-
else
|
37
|
-
name_string.gsub(%r{/(.?)}) do
|
42
|
+
def variable_name_to_class_name(name)
|
43
|
+
name.to_s.gsub(%r{/(.?)}) do
|
38
44
|
"::#{Regexp.last_match(1).upcase}"
|
39
45
|
end.gsub(/(?:^|_)(.)/) { Regexp.last_match(1).upcase }
|
40
46
|
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def find_definitions
|
44
|
-
log_deprecation('Fabrication::Support.find_definitions has been replaced by ' \
|
45
|
-
'Fabrication.manager.load_definitions and will be removed in 3.0.0.')
|
46
47
|
|
47
|
-
|
48
|
-
|
48
|
+
def find_definitions
|
49
|
+
puts 'DEPRECATION WARNING: Fabrication::Support.find_definitions has been replaced ' \
|
50
|
+
'by Fabrication.manager.load_definitions and will be removed in 3.0.0.'
|
51
|
+
Fabrication.manager.load_definitions
|
52
|
+
end
|
49
53
|
|
50
|
-
|
51
|
-
|
52
|
-
|
54
|
+
def hash_class
|
55
|
+
@hash_class ||= defined?(HashWithIndifferentAccess) ? HashWithIndifferentAccess : Hash
|
56
|
+
end
|
53
57
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
58
|
+
def singularize(string)
|
59
|
+
string.singularize
|
60
|
+
rescue StandardError
|
61
|
+
string.end_with?('s') ? string[0..-2] : string
|
62
|
+
end
|
59
63
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
64
|
+
def underscore(string)
|
65
|
+
string.gsub(/::/, '/')
|
66
|
+
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
67
|
+
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
68
|
+
.tr('-', '_')
|
69
|
+
.downcase
|
70
|
+
end
|
66
71
|
end
|
67
72
|
end
|
68
73
|
end
|
@@ -1,39 +1,37 @@
|
|
1
|
-
require 'singleton'
|
2
|
-
|
3
1
|
module Fabrication
|
4
2
|
class Transform
|
5
|
-
include Singleton
|
6
|
-
|
7
3
|
class << self
|
8
4
|
def apply_to(schematic, attributes_hash)
|
9
5
|
Fabrication.manager.load_definitions if Fabrication.manager.empty?
|
10
|
-
attributes_hash.inject({}) { |h, (k, v)| h.update(k =>
|
6
|
+
attributes_hash.inject({}) { |h, (k, v)| h.update(k => apply_transform(schematic, k, v)) }
|
11
7
|
end
|
12
8
|
|
13
9
|
def clear_all
|
14
|
-
|
15
|
-
|
10
|
+
@transforms = nil
|
11
|
+
@overrides = nil
|
16
12
|
end
|
17
13
|
|
18
14
|
def define(attribute, transform)
|
19
|
-
|
15
|
+
transforms[attribute] = transform
|
20
16
|
end
|
21
17
|
|
22
18
|
def only_for(schematic, attribute, transform)
|
23
|
-
|
19
|
+
overrides[schematic] = (overrides[schematic] || {}).merge!(attribute => transform)
|
24
20
|
end
|
25
|
-
end
|
26
21
|
|
27
|
-
|
28
|
-
@overrides ||= {}
|
29
|
-
end
|
22
|
+
private
|
30
23
|
|
31
|
-
|
32
|
-
|
33
|
-
|
24
|
+
def overrides
|
25
|
+
@overrides ||= {}
|
26
|
+
end
|
27
|
+
|
28
|
+
def apply_transform(schematic, attribute, value)
|
29
|
+
overrides.fetch(schematic, transforms)[attribute].call(value)
|
30
|
+
end
|
34
31
|
|
35
|
-
|
36
|
-
|
32
|
+
def transforms
|
33
|
+
@transforms ||= Hash.new(->(value) { value })
|
34
|
+
end
|
37
35
|
end
|
38
36
|
end
|
39
37
|
end
|
data/lib/fabrication/version.rb
CHANGED
data/lib/fabrication.rb
CHANGED
@@ -31,7 +31,7 @@ module Fabrication
|
|
31
31
|
|
32
32
|
module Generator
|
33
33
|
autoload :ActiveRecord, 'fabrication/generator/active_record'
|
34
|
-
autoload :
|
34
|
+
autoload :ActiveRecord4, 'fabrication/generator/active_record_4'
|
35
35
|
autoload :Mongoid, 'fabrication/generator/mongoid'
|
36
36
|
autoload :Sequel, 'fabrication/generator/sequel'
|
37
37
|
autoload :Base, 'fabrication/generator/base'
|
@@ -39,7 +39,7 @@ module Fabrication
|
|
39
39
|
|
40
40
|
def self.clear_definitions
|
41
41
|
manager.clear
|
42
|
-
Sequencer.clear
|
42
|
+
Sequencer.sequences.clear
|
43
43
|
end
|
44
44
|
|
45
45
|
def self.configure(&block)
|
@@ -47,12 +47,12 @@ module Fabrication
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def self.manager
|
50
|
-
Fabrication::Schematic::Manager.instance
|
50
|
+
@manager ||= Fabrication::Schematic::Manager.instance
|
51
51
|
end
|
52
52
|
|
53
53
|
def self.schematics
|
54
|
-
|
55
|
-
|
54
|
+
puts 'DEPRECATION WARNING: Fabrication.schematics has been replaced by '\
|
55
|
+
'Fabrication.manager and will be removed in 3.0.0.'
|
56
56
|
manager
|
57
57
|
end
|
58
58
|
end
|
@@ -63,7 +63,9 @@ def Fabricator(name, options = {}, &block)
|
|
63
63
|
end
|
64
64
|
|
65
65
|
def Fabricate(name, overrides = {}, &block)
|
66
|
-
Fabricate.create(name, overrides, &block)
|
66
|
+
Fabricate.create(name, overrides, &block).tap do |object|
|
67
|
+
Fabrication::Cucumber::Fabrications[name] = object if Fabrication::Config.register_with_steps?
|
68
|
+
end
|
67
69
|
end
|
68
70
|
# rubocop:enable Naming/MethodName
|
69
71
|
|
@@ -19,7 +19,7 @@ module Fabrication
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def self.source_root
|
22
|
-
File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
|
22
|
+
@source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
|
23
23
|
end
|
24
24
|
|
25
25
|
private
|
@@ -33,8 +33,6 @@ module Fabrication
|
|
33
33
|
end
|
34
34
|
rescue StandardError
|
35
35
|
# no table? no problem!
|
36
|
-
rescue LoadError
|
37
|
-
# cannot find model file. This means it was already destroyed, so just continue.
|
38
36
|
end
|
39
37
|
end
|
40
38
|
end
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fabrication
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0.beta.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Elliott
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-04-18 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Fabrication is an object generation framework for ActiveRecord, Mongoid,
|
14
|
-
|
14
|
+
Sequel, or any other Ruby object.
|
15
15
|
email:
|
16
16
|
- paul@codingfrontier.com
|
17
17
|
executables: []
|
@@ -32,7 +32,6 @@ files:
|
|
32
32
|
- lib/fabrication/errors/unknown_fabricator_error.rb
|
33
33
|
- lib/fabrication/generator/active_record.rb
|
34
34
|
- lib/fabrication/generator/base.rb
|
35
|
-
- lib/fabrication/generator/data_mapper.rb
|
36
35
|
- lib/fabrication/generator/mongoid.rb
|
37
36
|
- lib/fabrication/generator/sequel.rb
|
38
37
|
- lib/fabrication/railtie.rb
|
@@ -54,14 +53,7 @@ files:
|
|
54
53
|
homepage: http://fabricationgem.org
|
55
54
|
licenses:
|
56
55
|
- MIT
|
57
|
-
metadata:
|
58
|
-
bug_tracker_uri: https://gitlab.com/fabrication-gem/fabrication/-/issues
|
59
|
-
changelog_uri: https://gitlab.com/fabrication-gem/fabrication/-/blob/master/Changelog.markdown
|
60
|
-
documentation_uri: https://fabricationgem.org
|
61
|
-
homepage_uri: https://fabricationgem.org
|
62
|
-
mailing_list_uri: https://groups.google.com/g/fabricationgem
|
63
|
-
rubygems_mfa_required: 'true'
|
64
|
-
source_code_uri: https://gitlab.com/fabrication-gem/fabrication
|
56
|
+
metadata: {}
|
65
57
|
post_install_message:
|
66
58
|
rdoc_options: []
|
67
59
|
require_paths:
|
@@ -70,15 +62,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
70
62
|
requirements:
|
71
63
|
- - ">="
|
72
64
|
- !ruby/object:Gem::Version
|
73
|
-
version: 2.
|
65
|
+
version: 2.5.0
|
74
66
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
67
|
requirements:
|
76
|
-
- - "
|
68
|
+
- - ">"
|
77
69
|
- !ruby/object:Gem::Version
|
78
|
-
version:
|
70
|
+
version: 1.3.1
|
79
71
|
requirements: []
|
80
|
-
rubygems_version: 3.
|
72
|
+
rubygems_version: 3.1.4
|
81
73
|
signing_key:
|
82
74
|
specification_version: 4
|
83
|
-
summary:
|
75
|
+
summary: Implementing the factory pattern in Ruby so you don't have to.
|
84
76
|
test_files: []
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module Fabrication
|
2
|
-
module Generator
|
3
|
-
class DataMapper < Fabrication::Generator::Base
|
4
|
-
def self.supports?(klass)
|
5
|
-
defined?(::DataMapper) && klass.ancestors.include?(::DataMapper::Hook)
|
6
|
-
end
|
7
|
-
|
8
|
-
def build_instance
|
9
|
-
self._instance = resolved_class.new(_attributes)
|
10
|
-
end
|
11
|
-
|
12
|
-
protected
|
13
|
-
|
14
|
-
def persist
|
15
|
-
_instance.save
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|