fabrication 2.22.0 → 2.25.0

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: e5efca9d24fec1fce10f12981c38be52e1f848d180d0a6a3d8d873edeba23a5f
4
- data.tar.gz: 9809d319c49147c4a6bc112035692083fc3ce7900b3c46c9c6caf79bbd6fb019
3
+ metadata.gz: 25bf46c387fd321a6b7fb9f35b7a67862ced410dd318ad2c29a0bca8dd61479b
4
+ data.tar.gz: 367a2d9d5bc7213443a4de423447c99f9141e92c47fecc5ea0092df2b7821dbe
5
5
  SHA512:
6
- metadata.gz: 982151a8ccffa983acc0c73ccac23e289849d3171d87d8c2bb7eefe3f5b9e2bd3dceb6074d7ca7a0fa41b5ec371f6b1732acf5579c0dc0c7fa9b1a8171f7e50e
7
- data.tar.gz: fa154309b92888850eb7c744741046c2b27dcf6cd358a9a0dbdd4f96d31d0d72e5f25637231d453457380fec2b29fe198fef03501d84d19cdd968d535165e364
6
+ metadata.gz: 3ad4fc489704de95e48fd156f043ef22638d5e910e1d684db9e09798e9eb2064003056616cfbd08ec944aab4e024ad65f6bdca6d993e6f5a04aaa395bb48cf2c
7
+ data.tar.gz: 2f1cbf6bc060c00578234773534148eac605271f32e08b636aa873e232bc532da3e531c301830577dd1a2842a9592d4976485226d6804296110fea358a923c01
data/lib/fabricate.rb CHANGED
@@ -1,14 +1,14 @@
1
1
  class Fabricate
2
2
  def self.times(count, name, overrides = {}, &block)
3
- count.times.map { Fabricate(name, overrides, &block) }
3
+ Array.new(count).map { Fabricate(name, overrides, &block) }
4
4
  end
5
5
 
6
6
  def self.build_times(count, name, overrides = {}, &block)
7
- count.times.map { Fabricate.build(name, overrides, &block) }
7
+ Array.new(count).map { Fabricate.build(name, overrides, &block) }
8
8
  end
9
9
 
10
10
  def self.attributes_for_times(count, name, overrides = {}, &block)
11
- count.times.map { Fabricate.attributes_for(name, overrides, &block) }
11
+ Array.new(count).map { Fabricate.attributes_for(name, overrides, &block) }
12
12
  end
13
13
 
14
14
  def self.attributes_for(name, overrides = {}, &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,7 +31,7 @@ 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
 
@@ -20,7 +20,7 @@ module Fabrication
20
20
  end
21
21
 
22
22
  def n(count, attrs = {})
23
- count.times.map { make(attrs) }.tap { |o| remember(o) }
23
+ Array.new(count).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_eval(&callback)
57
+ self._instance = instance_exec(_transient_attributes, &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)
62
+ self._instance = _klass.new(*callback.call(_transient_attributes))
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.keys.include?(k) }
107
+ _attributes.reject! { |k| _transient_attributes.key?(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) && klass.ancestors.include?(::Sequel::Model)
10
+ defined?(::Sequel) && defined?(::Sequel::Model) && klass.ancestors.include?(::Sequel::Model)
11
11
  end
12
12
 
13
13
  def set_attributes
@@ -18,7 +18,7 @@ module Fabrication
18
18
  end
19
19
 
20
20
  def process_block(&block)
21
- Fabrication::Schematic::Evaluator.new.process(self, &block) if block_given?
21
+ Fabrication::Schematic::Evaluator.new.process(self, &block) if block
22
22
  end
23
23
 
24
24
  def attribute(name)
@@ -55,14 +55,16 @@ 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 |folder|
59
- Dir.glob(File.join(prefix.to_s, folder, '**', '*.rb')).sort.each do |file|
60
- load file
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
61
65
  end
62
66
  end
63
67
  end
64
- rescue StandardError => e
65
- raise e
66
68
  ensure
67
69
  freeze
68
70
  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_given?
7
+ if block
8
8
  sequence_blocks[name] = block.to_proc
9
9
  else
10
10
  sequence_blocks[name] ||= ->(i) { i }
@@ -40,14 +40,20 @@ module Fabrication
40
40
  end
41
41
 
42
42
  def variable_name_to_class_name(name)
43
- name.to_s.gsub(%r{/(.?)}) do
44
- "::#{Regexp.last_match(1).upcase}"
45
- end.gsub(/(?:^|_)(.)/) { Regexp.last_match(1).upcase }
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
46
52
  end
47
53
 
48
54
  def find_definitions
49
55
  puts 'DEPRECATION WARNING: Fabrication::Support.find_definitions has been replaced ' \
50
- 'by Fabrication.manager.load_definitions and will be removed in 3.0.0.'
56
+ 'by Fabrication.manager.load_definitions and will be removed in 3.0.0.'
51
57
  Fabrication.manager.load_definitions
52
58
  end
53
59
 
@@ -1,3 +1,3 @@
1
1
  module Fabrication
2
- VERSION = '2.22.0'.freeze
2
+ VERSION = '2.25.0'.freeze
3
3
  end
data/lib/fabrication.rb CHANGED
@@ -53,7 +53,7 @@ module Fabrication
53
53
 
54
54
  def self.schematics
55
55
  puts 'DEPRECATION WARNING: Fabrication.schematics has been replaced by '\
56
- 'Fabrication.manager and will be removed in 3.0.0.'
56
+ 'Fabrication.manager and will be removed in 3.0.0.'
57
57
  manager
58
58
  end
59
59
  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.22.0
4
+ version: 2.25.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Elliott
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-25 00:00:00.000000000 Z
11
+ date: 2022-01-28 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Fabrication is an object generation framework for ActiveRecord, Mongoid,
14
14
  DataMapper, Sequel, or any other Ruby object.
@@ -63,14 +63,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
63
63
  requirements:
64
64
  - - ">="
65
65
  - !ruby/object:Gem::Version
66
- version: 2.5.0
66
+ version: 2.6.0
67
67
  required_rubygems_version: !ruby/object:Gem::Requirement
68
68
  requirements:
69
69
  - - ">="
70
70
  - !ruby/object:Gem::Version
71
71
  version: '0'
72
72
  requirements: []
73
- rubygems_version: 3.1.4
73
+ rubygems_version: 3.2.32
74
74
  signing_key:
75
75
  specification_version: 4
76
76
  summary: Implementing the factory pattern in Ruby so you don't have to.