fabrication 2.17.0 → 2.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/fabrication.rb +1 -0
- data/lib/fabrication/config.rb +3 -0
- data/lib/fabrication/errors/infinite_recursion_error.rb +5 -0
- data/lib/fabrication/schematic/definition.rb +12 -4
- data/lib/fabrication/schematic/manager.rb +10 -0
- data/lib/fabrication/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b16cf8ca405caaf21ab076cd40a2ea7d8c2be30a
|
4
|
+
data.tar.gz: b785f882534a6d5139ca43bca6c8240dcd43efdb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: edb17b2fe50e6b6076b921576039e25e8aee00ffcce70f0ffdde721912617d5e26db164cd8bb1d291adc578dd1a420fbc4e7304586a46ec8695803eec908b657
|
7
|
+
data.tar.gz: 984e757e5f90514b95cab7d32ad776d0a9b04a0550773e28b74732059d27ff39ae71d3feb3b379183f61a4b90629b970c159fce75fb15eb1d106fb6af3cc3adf
|
data/lib/fabrication.rb
CHANGED
@@ -12,6 +12,7 @@ module Fabrication
|
|
12
12
|
autoload :UnfabricatableError, 'fabrication/errors/unfabricatable_error'
|
13
13
|
autoload :UnknownFabricatorError, 'fabrication/errors/unknown_fabricator_error'
|
14
14
|
autoload :MisplacedFabricateError, 'fabrication/errors/misplaced_fabricate_error'
|
15
|
+
autoload :InfiniteRecursionError, 'fabrication/errors/infinite_recursion_error'
|
15
16
|
|
16
17
|
module Schematic
|
17
18
|
autoload :Attribute, 'fabrication/schematic/attribute'
|
data/lib/fabrication/config.rb
CHANGED
@@ -53,5 +53,8 @@ module Fabrication
|
|
53
53
|
def generator_for(default_generators, klass)
|
54
54
|
(generators + default_generators).detect { |gen| gen.supports?(klass) }
|
55
55
|
end
|
56
|
+
|
57
|
+
def recursion_limit; @recursion_limit ||= 20 end
|
58
|
+
def recursion_limit=(limit); @recursion_limit = limit end
|
56
59
|
end
|
57
60
|
end
|
@@ -54,11 +54,12 @@ class Fabrication::Schematic::Definition
|
|
54
54
|
end
|
55
55
|
|
56
56
|
def build(overrides={}, &block)
|
57
|
+
Fabrication.manager.prevent_recursion!
|
57
58
|
if Fabrication.manager.to_params_stack.any?
|
58
59
|
to_params(overrides, &block)
|
59
60
|
else
|
60
61
|
begin
|
61
|
-
Fabrication.manager.build_stack <<
|
62
|
+
Fabrication.manager.build_stack << name
|
62
63
|
merge(overrides, &block).instance_eval do
|
63
64
|
generator.new(klass).build(sorted_attributes, callbacks)
|
64
65
|
end
|
@@ -69,19 +70,26 @@ class Fabrication::Schematic::Definition
|
|
69
70
|
end
|
70
71
|
|
71
72
|
def fabricate(overrides={}, &block)
|
73
|
+
Fabrication.manager.prevent_recursion!
|
72
74
|
if Fabrication.manager.build_stack.any?
|
73
75
|
build(overrides, &block)
|
74
76
|
elsif Fabrication.manager.to_params_stack.any?
|
75
77
|
to_params(overrides, &block)
|
76
78
|
else
|
77
|
-
|
78
|
-
|
79
|
+
begin
|
80
|
+
Fabrication.manager.create_stack << name
|
81
|
+
merge(overrides, &block).instance_eval do
|
82
|
+
generator.new(klass).create(sorted_attributes, callbacks)
|
83
|
+
end
|
84
|
+
ensure
|
85
|
+
Fabrication.manager.create_stack.pop
|
79
86
|
end
|
80
87
|
end
|
81
88
|
end
|
82
89
|
|
83
90
|
def to_params(overrides={}, &block)
|
84
|
-
Fabrication.manager.
|
91
|
+
Fabrication.manager.prevent_recursion!
|
92
|
+
Fabrication.manager.to_params_stack << name
|
85
93
|
merge(overrides, &block).instance_eval do
|
86
94
|
generator.new(klass).to_params(sorted_attributes)
|
87
95
|
end
|
@@ -33,6 +33,10 @@ class Fabrication::Schematic::Manager
|
|
33
33
|
schematics[name.to_sym]
|
34
34
|
end
|
35
35
|
|
36
|
+
def create_stack
|
37
|
+
@create_stack ||= []
|
38
|
+
end
|
39
|
+
|
36
40
|
def build_stack
|
37
41
|
@build_stack ||= []
|
38
42
|
end
|
@@ -56,6 +60,12 @@ class Fabrication::Schematic::Manager
|
|
56
60
|
freeze
|
57
61
|
end
|
58
62
|
|
63
|
+
def prevent_recursion!
|
64
|
+
(create_stack + build_stack + to_params_stack).group_by(&:to_sym).each do |name, values|
|
65
|
+
raise Fabrication::InfiniteRecursionError.new(name) if values.length > Fabrication::Config.recursion_limit
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
59
69
|
protected
|
60
70
|
|
61
71
|
def raise_if_registered(name)
|
data/lib/fabrication/version.rb
CHANGED
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.
|
4
|
+
version: 2.18.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: 2017-10-
|
11
|
+
date: 2017-10-09 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.
|
@@ -26,6 +26,7 @@ files:
|
|
26
26
|
- lib/fabrication/config.rb
|
27
27
|
- lib/fabrication/cucumber/step_fabricator.rb
|
28
28
|
- lib/fabrication/errors/duplicate_fabricator_error.rb
|
29
|
+
- lib/fabrication/errors/infinite_recursion_error.rb
|
29
30
|
- lib/fabrication/errors/misplaced_fabricate_error.rb
|
30
31
|
- lib/fabrication/errors/unfabricatable_error.rb
|
31
32
|
- lib/fabrication/errors/unknown_fabricator_error.rb
|
@@ -62,7 +63,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
62
63
|
requirements:
|
63
64
|
- - ">="
|
64
65
|
- !ruby/object:Gem::Version
|
65
|
-
version:
|
66
|
+
version: 2.2.0
|
66
67
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
68
|
requirements:
|
68
69
|
- - ">="
|