fabrication 2.28.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: df854c441daf0accdb476682c98e8dcc2fab18fe239d182ccfe2946e16995921
4
- data.tar.gz: d6cf1bfa72594c9255243643eed956f97af1fd976bb8768fe458410f54e4d1dd
3
+ metadata.gz: 20a02618a5107ba5850de6da2bd58ae428d33d8163ab3c71f9233574780998df
4
+ data.tar.gz: 33bac0b9d796da2d94adf3a8eb8940ff8766c36c9435429a03a1da0dd1efb8ad
5
5
  SHA512:
6
- metadata.gz: 4783af273421b7799092a0bcc75c86a66d8f85f22a98d18354935010ccabc4a8fd32aa0eef5c814bab7257ff29cfef8db3e58160016d04a6f77b1480b92a80f9
7
- data.tar.gz: 6fdec94bac094143b78d8135b56219c8e2faaa9136035fc1dcd309e0d7b44978991c12664ae422722debadb13ffe4c2396cde01e3e384c495d08d29fb869fa8b
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
- Array.new(count).map { Fabricate(name, overrides, &block) }
3
+ count.times.map { Fabricate(name, overrides, &block) }
4
4
  end
5
5
 
6
6
  def self.build_times(count, name, overrides = {}, &block)
7
- Array.new(count).map { Fabricate.build(name, overrides, &block) }
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
- Array.new(count).map { Fabricate.attributes_for(name, overrides, &block) }
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.notifiers.each do |notifier|
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).tap do |object|
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)
@@ -21,7 +21,7 @@ module Fabrication
21
21
 
22
22
  def fabricator_dir
23
23
  puts 'DEPRECATION WARNING: Fabrication::Config.fabricator_dir has been ' \
24
- 'replaced by Fabrication::Config.fabricator_path'
24
+ 'replaced by Fabrication::Config.fabricator_path'
25
25
  fabricator_path
26
26
  end
27
27
 
@@ -31,11 +31,11 @@ module Fabrication
31
31
 
32
32
  def fabricator_dir=(folders)
33
33
  puts 'DEPRECATION WARNING: Fabrication::Config.fabricator_dir has been ' \
34
- 'replaced by Fabrication::Config.fabricator_path'
34
+ 'replaced by Fabrication::Config.fabricator_path'
35
35
  self.fabricator_path = folders
36
36
  end
37
37
 
38
- attr_writer :sequence_start
38
+ attr_writer :sequence_start, :register_with_steps
39
39
 
40
40
  def sequence_start
41
41
  @sequence_start ||= 0
@@ -50,6 +50,10 @@ module Fabrication
50
50
  end
51
51
  alias path_prefixes path_prefix
52
52
 
53
+ def register_with_steps?
54
+ @register_with_steps ||= nil
55
+ end
56
+
53
57
  def generators
54
58
  @generators ||= []
55
59
  end
@@ -65,24 +69,5 @@ module Fabrication
65
69
  def recursion_limit=(limit)
66
70
  @recursion_limit = limit
67
71
  end
68
-
69
- def register_with_steps=(value)
70
- puts 'DEPRECATION WARNING: Fabrication::Config.register_with_steps has been ' \
71
- 'deprecated. Please regenerate your cucumber steps with `rails g fabrication:cucumber_steps'
72
-
73
- return unless value
74
-
75
- register_notifier do |name, object|
76
- Fabrication::Cucumber::Fabrications[name] = object
77
- end
78
- end
79
-
80
- def notifiers
81
- @notifiers ||= []
82
- end
83
-
84
- def register_notifier(&block)
85
- notifiers.push(block)
86
- end
87
72
  end
88
73
  end
@@ -20,7 +20,7 @@ module Fabrication
20
20
  end
21
21
 
22
22
  def n(count, attrs = {})
23
- Array.new(count).map { make(attrs) }.tap { |o| remember(o) }
23
+ count.times.map { make(attrs) }.tap { |o| remember(o) }
24
24
  end
25
25
 
26
26
  # rubocop:disable Naming/PredicateName
@@ -6,8 +6,8 @@ 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
- (defined?(::ActiveRecord) && defined?(::ActiveRecord::Base) &&
10
- klass.ancestors.include?(::ActiveRecord::Base)) || false
9
+ defined?(::ActiveRecord) && defined?(::ActiveRecord::Base) &&
10
+ klass.ancestors.include?(::ActiveRecord::Base) || false
11
11
  end
12
12
 
13
13
  def build_instance
@@ -54,12 +54,12 @@ module Fabrication
54
54
  end
55
55
 
56
56
  def build_instance_with_constructor_override(callback)
57
- self._instance = instance_exec(_transient_attributes, &callback)
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 = _klass.new(*callback.call(_transient_attributes))
62
+ self._instance = _klass.new(*callback.call)
63
63
  set_attributes
64
64
  end
65
65
 
@@ -104,7 +104,7 @@ module Fabrication
104
104
  _attributes[attribute.name] = attribute.processed_value(_attributes)
105
105
  _transient_attributes[attribute.name] = _attributes[attribute.name] if attribute.transient?
106
106
  end
107
- _attributes.reject! { |k| _transient_attributes.key?(k) }
107
+ _attributes.reject! { |k| _transient_attributes.keys.include?(k) }
108
108
  end
109
109
  end
110
110
  end
@@ -7,7 +7,7 @@ module Fabrication
7
7
  end
8
8
 
9
9
  def self.supports?(klass)
10
- defined?(::Sequel) && defined?(::Sequel::Model) && klass.ancestors.include?(::Sequel::Model)
10
+ defined?(::Sequel) && klass.ancestors.include?(::Sequel::Model)
11
11
  end
12
12
 
13
13
  def set_attributes
@@ -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 block
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 |path|
59
- if File.file?(path)
60
- load path
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
@@ -4,7 +4,7 @@ module Fabrication
4
4
 
5
5
  def self.sequence(name = DEFAULT, start = nil, &block)
6
6
  idx = sequences[name] ||= start || Fabrication::Config.sequence_start
7
- if block
7
+ if block_given?
8
8
  sequence_blocks[name] = block.to_proc
9
9
  else
10
10
  sequence_blocks[name] ||= ->(i) { i }
@@ -40,20 +40,14 @@ module Fabrication
40
40
  end
41
41
 
42
42
  def variable_name_to_class_name(name)
43
- name_string = name.to_s
44
-
45
- if name_string.respond_to?(:camelize)
46
- name_string.camelize
47
- else
48
- name_string.gsub(%r{/(.?)}) do
49
- "::#{Regexp.last_match(1).upcase}"
50
- end.gsub(/(?:^|_)(.)/) { Regexp.last_match(1).upcase }
51
- end
43
+ name.to_s.gsub(%r{/(.?)}) do
44
+ "::#{Regexp.last_match(1).upcase}"
45
+ end.gsub(/(?:^|_)(.)/) { Regexp.last_match(1).upcase }
52
46
  end
53
47
 
54
48
  def find_definitions
55
49
  puts 'DEPRECATION WARNING: Fabrication::Support.find_definitions has been replaced ' \
56
- 'by Fabrication.manager.load_definitions and will be removed in 3.0.0.'
50
+ 'by Fabrication.manager.load_definitions and will be removed in 3.0.0.'
57
51
  Fabrication.manager.load_definitions
58
52
  end
59
53
 
@@ -1,3 +1,3 @@
1
1
  module Fabrication
2
- VERSION = '2.28.0'.freeze
2
+ VERSION = '3.0.0.beta.1'.freeze
3
3
  end
data/lib/fabrication.rb CHANGED
@@ -32,7 +32,6 @@ module Fabrication
32
32
  module Generator
33
33
  autoload :ActiveRecord, 'fabrication/generator/active_record'
34
34
  autoload :ActiveRecord4, 'fabrication/generator/active_record_4'
35
- autoload :DataMapper, 'fabrication/generator/data_mapper'
36
35
  autoload :Mongoid, 'fabrication/generator/mongoid'
37
36
  autoload :Sequel, 'fabrication/generator/sequel'
38
37
  autoload :Base, 'fabrication/generator/base'
@@ -53,7 +52,7 @@ module Fabrication
53
52
 
54
53
  def self.schematics
55
54
  puts 'DEPRECATION WARNING: Fabrication.schematics has been replaced by '\
56
- 'Fabrication.manager and will be removed in 3.0.0.'
55
+ 'Fabrication.manager and will be removed in 3.0.0.'
57
56
  manager
58
57
  end
59
58
  end
@@ -64,7 +63,9 @@ def Fabricator(name, options = {}, &block)
64
63
  end
65
64
 
66
65
  def Fabricate(name, overrides = {}, &block)
67
- 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
68
69
  end
69
70
  # rubocop:enable Naming/MethodName
70
71
 
@@ -1,8 +1,6 @@
1
1
  World(FabricationMethods)
2
2
 
3
- Fabrication::Config.register_notifier do |name, object|
4
- Fabrication::Cucumber::Fabrications[name] = object
5
- end
3
+ Fabrication::Config.register_with_steps = true
6
4
 
7
5
  def with_ivars(fabricator)
8
6
  @they = yield fabricator
@@ -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: 2.28.0
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: 2022-03-29 00:00:00.000000000 Z
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
- DataMapper, Sequel, or any other Ruby object.
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.6.0
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: '0'
70
+ version: 1.3.1
79
71
  requirements: []
80
- rubygems_version: 3.2.32
72
+ rubygems_version: 3.1.4
81
73
  signing_key:
82
74
  specification_version: 4
83
- summary: Generates object instances for test suites, seed files, etc.
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 = _klass.new(_attributes)
10
- end
11
-
12
- protected
13
-
14
- def persist
15
- _instance.save
16
- end
17
- end
18
- end
19
- end