faker_maker 2.1.2 → 4.0.0.beta1
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/.github/workflows/ruby.yml +13 -14
- data/.gitignore +4 -0
- data/.rubocop.yml +4 -3
- data/Gemfile +6 -0
- data/README.md +7 -1
- data/lib/faker_maker/attribute.rb +10 -1
- data/lib/faker_maker/factory.rb +122 -36
- data/lib/faker_maker/version.rb +1 -1
- data/lib/faker_maker.rb +1 -1
- data/usefakermaker.com/.gitignore +5 -0
- data/usefakermaker.com/404.html +25 -0
- data/usefakermaker.com/Gemfile +39 -0
- data/usefakermaker.com/README.md +5 -0
- data/usefakermaker.com/_config.yml +299 -0
- data/usefakermaker.com/_config.yml.orig +55 -0
- data/usefakermaker.com/_data/navigation.yml +51 -0
- data/usefakermaker.com/_data/ui-text.yml +2132 -0
- data/usefakermaker.com/_site/assets/css/main.css.map +1 -1
- data/usefakermaker.com/_site/assets/js/lunr/lunr-store.js +1 -10
- data/usefakermaker.com/_site/feed.xml +1 -17
- data/usefakermaker.com/_site/sitemap.xml +0 -10
- data/usefakermaker.com/about.markdown +18 -0
- data/usefakermaker.com/docs/contributing/index.md +7 -0
- data/{docs/installation.md → usefakermaker.com/docs/installing/index.md} +3 -5
- data/{docs/usage/arrays.md → usefakermaker.com/docs/usage/arrays/index.md} +2 -6
- data/{docs/usage/building_instances.md → usefakermaker.com/docs/usage/building-instances/index.md} +10 -12
- data/{docs/usage/chaos.md → usefakermaker.com/docs/usage/chaos/index.md} +6 -10
- data/{docs/usage/destroying_factories.md → usefakermaker.com/docs/usage/destroying-factories/index.md} +7 -9
- data/{docs/usage/embedding_factories.md → usefakermaker.com/docs/usage/embedding-factories/index.md} +42 -9
- data/{docs/usage → usefakermaker.com/docs/usage/getting-started}/index.md +12 -15
- data/{docs/usage/audit_logs.md → usefakermaker.com/docs/usage/history-logging/index.md} +4 -4
- data/{docs/usage/inheritance.md → usefakermaker.com/docs/usage/inheritance/index.md} +7 -9
- data/{docs/usage/json_field_names.md → usefakermaker.com/docs/usage/json-field-names/index.md} +2 -6
- data/{docs/usage/lifecycle_hooks.md → usefakermaker.com/docs/usage/lifecycle-hooks/index.md} +3 -7
- data/{docs/usage/dependencies.md → usefakermaker.com/docs/usage/managing-dependencies/index.md} +2 -6
- data/{docs/usage/omitting_fields copy.md → usefakermaker.com/docs/usage/omitting-fields/index.md} +4 -8
- data/usefakermaker.com/pages/about/index.md +20 -0
- data/usefakermaker.com/pages/index.markdown +27 -0
- metadata +30 -32
- data/docs/.bundle/config +0 -2
- data/docs/.keep +0 -1
- data/docs/_config.yml +0 -8
- data/docs/contributing.md +0 -9
- data/docs/credits.md +0 -9
- data/docs/index.md +0 -21
- data/docs/logo.png +0 -0
- data/usefakermaker.com/_site/404.html +0 -213
- data/usefakermaker.com/_site/about/index.html +0 -10
- data/usefakermaker.com/_site/index.html +0 -258
- data/usefakermaker.com/_site/jekyll/update/welcome-to-jekyll/index.html +0 -18
- /data/usefakermaker.com/{_site/assets → assets}/images/pug.png +0 -0
- /data/usefakermaker.com/{_site/assets → assets}/images/unipug.svg +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2010123a071b807d1400f16c16cbaf58b4db86507224c72f50847affcfbc1bd4
|
|
4
|
+
data.tar.gz: 8e72393016c7a54106bc1aca8ecccf46d35c94ee1b9fb4b95c6b49ba5bbd2dfc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f8f73cb6e888ef7f49abd66959c64916df617f0254a98b0ca022c19dbc45aef6e259d92d9186d57128f9180c094c46af4776fb3c087ec3fce94eff1cead58eb0
|
|
7
|
+
data.tar.gz: b7baa192ddf36b18f6a696d4cec08b8372e57fd95a44d0397a8a6f94f298938e449553aec1d6b03c32a63544589c421afb46c080f67a699eaace38d5d9f15eaf
|
data/.github/workflows/ruby.yml
CHANGED
|
@@ -10,28 +10,27 @@ name: Ruby
|
|
|
10
10
|
on:
|
|
11
11
|
push:
|
|
12
12
|
pull_request:
|
|
13
|
-
branches: [
|
|
13
|
+
branches: ["master"]
|
|
14
14
|
|
|
15
15
|
permissions:
|
|
16
16
|
contents: read
|
|
17
17
|
|
|
18
18
|
jobs:
|
|
19
19
|
test:
|
|
20
|
-
|
|
21
20
|
runs-on: ubuntu-latest
|
|
22
21
|
strategy:
|
|
23
22
|
matrix:
|
|
24
|
-
ruby-version: ["3.0", "3.1", "3.2"]
|
|
23
|
+
ruby-version: ["3.0", "3.1", "3.2", "3.3", "3.4"]
|
|
25
24
|
|
|
26
25
|
steps:
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
26
|
+
- uses: actions/checkout@v3
|
|
27
|
+
- name: Set up Ruby
|
|
28
|
+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
|
29
|
+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
|
30
|
+
# uses: ruby/setup-ruby@v1
|
|
31
|
+
uses: ruby/setup-ruby@v1 # v1.146.0
|
|
32
|
+
with:
|
|
33
|
+
ruby-version: ${{ matrix.ruby-version }}
|
|
34
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
|
35
|
+
- name: Run tests
|
|
36
|
+
run: bundle exec rake
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Layout/SpaceInsideParens:
|
|
2
2
|
Enabled: false
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
Layout/LineLength:
|
|
5
5
|
Max: 120
|
|
6
6
|
|
|
7
7
|
Metrics/ModuleLength:
|
|
@@ -32,7 +32,7 @@ Style/HashEachMethods:
|
|
|
32
32
|
|
|
33
33
|
Style/HashTransformKeys:
|
|
34
34
|
Enabled: true
|
|
35
|
-
|
|
35
|
+
|
|
36
36
|
Style/HashTransformValues:
|
|
37
37
|
Enabled: true
|
|
38
38
|
|
|
@@ -52,4 +52,5 @@ Metrics/PerceivedComplexity:
|
|
|
52
52
|
Max: 10
|
|
53
53
|
|
|
54
54
|
AllCops:
|
|
55
|
-
|
|
55
|
+
TargetRubyVersion: 3.4
|
|
56
|
+
NewCops: enable
|
data/Gemfile
CHANGED
data/README.md
CHANGED
|
@@ -21,4 +21,10 @@
|
|
|
21
21
|
|
|
22
22
|
FakerMaker is a simple factory builder so you can throw away your fixtures and generate test data instead.
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
Sometimes you need generate data; something testers need to do a lot. Often, a bunch of fixtures will be built by hand, carefully maintained and curated, until the API or schema or something changes and all the fixtures need to be pruned before the tests pass again. This drives testers into building fixtures which individually cover lots of acceptance critera just so that they can drive down the number of them they have to maintain until the fixtures don’t resemble anything like realistic criteria.
|
|
25
|
+
|
|
26
|
+
If you’re testing a Rails application, you can use the awesome FactoryBot to generate faked model instances but what if you’re not using Rails or you don’t have model classes or you’re testing an API? This is what Faker Maker aims to help with.
|
|
27
|
+
|
|
28
|
+
It is designed to resemble the Factory Bot gem but without needing an existing class definition to back its object and so it goes without saying that it offers no persistence mechanism. Its purpose is to provide a simple framework for generating data to test JSON APIs and is intended to be used with the Faker gem (but has no dependency upon it).
|
|
29
|
+
|
|
30
|
+
Read the [documentation here](https://usefakermaker.com).
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
module FakerMaker
|
|
4
4
|
# Attributes describe the fields of classes
|
|
5
5
|
class Attribute
|
|
6
|
-
attr_reader :name, :block, :translation, :required, :optional, :optional_weighting
|
|
6
|
+
attr_reader :name, :block, :translation, :required, :optional, :optional_weighting
|
|
7
7
|
|
|
8
8
|
DEFAULT_OPTIONAL_WEIGHTING = 0.5
|
|
9
9
|
|
|
@@ -25,6 +25,15 @@ module FakerMaker
|
|
|
25
25
|
end
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
+
# Return an array of factory instances
|
|
29
|
+
def embedded_factories
|
|
30
|
+
@embedded_factories.map { |name| FakerMaker[name] }
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def embedded_factories?
|
|
34
|
+
@embedded_factories.any?
|
|
35
|
+
end
|
|
36
|
+
|
|
28
37
|
def array?
|
|
29
38
|
forced_array? || @array
|
|
30
39
|
end
|
data/lib/faker_maker/factory.rb
CHANGED
|
@@ -5,8 +5,26 @@ module FakerMaker
|
|
|
5
5
|
# Factories construct instances of a fake
|
|
6
6
|
class Factory
|
|
7
7
|
include Auditable
|
|
8
|
+
|
|
8
9
|
attr_reader :name, :class_name, :parent, :chaos_selected_attributes
|
|
9
10
|
|
|
11
|
+
# Create a new +Factory+ object.
|
|
12
|
+
#
|
|
13
|
+
# This method does not automatically register the factory,see
|
|
14
|
+
# FakerMaker#register_factory
|
|
15
|
+
#
|
|
16
|
+
# Options:
|
|
17
|
+
# - +:class_name+ - override the default class name that FakerMaker will generate.
|
|
18
|
+
# This is useful in the case of collisions with existing classes or keywords.
|
|
19
|
+
# - +:parent+ - the parent factory from which this factory inherits attributes.
|
|
20
|
+
# Instances built by this factory will have a class which inherits from the parent's
|
|
21
|
+
# class.
|
|
22
|
+
# - +:naming+ - one of:
|
|
23
|
+
# - +nil+ (default) - use field names as the method name and in JSON conversion
|
|
24
|
+
# - +:json+ - use field names as the method name but convert when rendering JSON, e.g.
|
|
25
|
+
# +hello_world+ becomes +helloWorld+
|
|
26
|
+
# - +:json_capitalised+ (or +:json_capitalized+) - as +:json+ but with the first letter
|
|
27
|
+
# captialised, e.g. +hello_world+ becomes +HelloWorld+
|
|
10
28
|
def initialize( name, options = {} )
|
|
11
29
|
assert_valid_options options
|
|
12
30
|
@name = name.respond_to?(:to_sym) ? name.to_sym : name.to_s.underscore.to_sym
|
|
@@ -26,14 +44,16 @@ module FakerMaker
|
|
|
26
44
|
@parent = options[:parent]
|
|
27
45
|
end
|
|
28
46
|
|
|
47
|
+
# Get the Class of the parent for this factory
|
|
29
48
|
def parent_class
|
|
30
49
|
if @parent
|
|
31
|
-
|
|
50
|
+
FakerMaker::Factory.const_get( FakerMaker[@parent].class_name )
|
|
32
51
|
else
|
|
33
52
|
Object
|
|
34
53
|
end
|
|
35
54
|
end
|
|
36
55
|
|
|
56
|
+
# Attach a FakerMaker::Attribute to this Factory
|
|
37
57
|
def attach_attribute( attribute )
|
|
38
58
|
@attributes << attribute
|
|
39
59
|
end
|
|
@@ -42,14 +62,11 @@ module FakerMaker
|
|
|
42
62
|
@instance ||= instantiate
|
|
43
63
|
end
|
|
44
64
|
|
|
45
|
-
def build( attributes: {}, chaos: false
|
|
46
|
-
if kwargs.present?
|
|
47
|
-
validate_deprecated_build(kwargs)
|
|
48
|
-
attributes = kwargs
|
|
49
|
-
end
|
|
50
|
-
|
|
65
|
+
def build( attributes: {}, chaos: false )
|
|
51
66
|
@instance = nil
|
|
52
67
|
before_build if respond_to? :before_build
|
|
68
|
+
|
|
69
|
+
# TODO: make this cleverer to handle nested attributes
|
|
53
70
|
assert_only_known_attributes_for_override( attributes )
|
|
54
71
|
|
|
55
72
|
assert_chaos_options chaos if chaos
|
|
@@ -57,17 +74,23 @@ module FakerMaker
|
|
|
57
74
|
optional_attributes
|
|
58
75
|
required_attributes
|
|
59
76
|
|
|
60
|
-
populate_instance
|
|
77
|
+
populate_instance(instance, attributes, chaos:)
|
|
61
78
|
yield instance if block_given?
|
|
79
|
+
|
|
62
80
|
after_build if respond_to? :after_build
|
|
63
81
|
audit(@instance) if FakerMaker.configuration.audit?
|
|
64
82
|
instance
|
|
65
83
|
end
|
|
66
84
|
|
|
85
|
+
# Construct a Class object which will become the parent type of objects built
|
|
86
|
+
# by this factory.
|
|
87
|
+
#
|
|
88
|
+
# The Class object will be created and the attributes added to it. The returned value
|
|
89
|
+
# is a Ruby Class which can be instantiated.
|
|
67
90
|
def assemble
|
|
68
91
|
if @klass.nil?
|
|
69
92
|
@klass = Class.new parent_class
|
|
70
|
-
|
|
93
|
+
FakerMaker::Factory.const_set @class_name, @klass
|
|
71
94
|
attach_attributes_to_class
|
|
72
95
|
attach_json_overrides_to_class
|
|
73
96
|
end
|
|
@@ -91,7 +114,7 @@ module FakerMaker
|
|
|
91
114
|
unless @json_key_map
|
|
92
115
|
@json_key_map = {}.with_indifferent_access
|
|
93
116
|
@json_key_map.merge!( FakerMaker[parent].json_key_map ) if parent?
|
|
94
|
-
attributes.each_with_object( @json_key_map ) do |attr, map|
|
|
117
|
+
attributes(include_embeddings: false).each_with_object( @json_key_map ) do |attr, map|
|
|
95
118
|
key = if attr.translation?
|
|
96
119
|
attr.translation
|
|
97
120
|
elsif @naming_strategy
|
|
@@ -106,29 +129,86 @@ module FakerMaker
|
|
|
106
129
|
@json_key_map
|
|
107
130
|
end
|
|
108
131
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
132
|
+
# Returns a transformed list of attribute names from the `attributes` array.
|
|
133
|
+
# For each item in the array:
|
|
134
|
+
# - If the item is a Hash, recursively transforms its keys and values,
|
|
135
|
+
# replacing keys with their `name` and applying the same transformation to values.
|
|
136
|
+
# - Otherwise, replaces the item with its `name`.
|
|
137
|
+
#
|
|
138
|
+
# @return [Array] An array (possibly nested) of attribute names, with hashes' keys replaced by their `name`.
|
|
139
|
+
def attribute_names
|
|
140
|
+
transform = lambda do |arr|
|
|
141
|
+
arr.map do |item|
|
|
142
|
+
if item.is_a?(Hash)
|
|
143
|
+
item.transform_keys(&:name).transform_values { |v| transform.call(v) }
|
|
144
|
+
else
|
|
145
|
+
item.name
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
transform.call(attributes)
|
|
112
150
|
end
|
|
113
151
|
|
|
114
|
-
|
|
152
|
+
# Returns a collection of attributes for the factory, optionally including embedded factory attributes.
|
|
153
|
+
#
|
|
154
|
+
# @param collection [Array] an optional array of attributes to start with (default: empty array)
|
|
155
|
+
# @param include_embeddings [Boolean] whether to include attributes from embedded factories (default: true)
|
|
156
|
+
# @return [Array] the collection of attributes, possibly including embedded factory attributes as hashes
|
|
157
|
+
#
|
|
158
|
+
# If the factory has a parent, its attributes are merged in. Attributes without embedded factories are added directly.
|
|
159
|
+
# If `include_embeddings` is true, attributes with embedded factories are added as hashes mapping the attribute to the
|
|
160
|
+
# flattened attributes of its embedded factories. If false, only the attribute itself is added.
|
|
161
|
+
def attributes( collection = [], include_embeddings: true )
|
|
115
162
|
collection |= FakerMaker[parent].attributes( collection ) if parent?
|
|
116
|
-
collection
|
|
163
|
+
collection |= @attributes.reject { |attr| attr.embedded_factories.any? }
|
|
164
|
+
|
|
165
|
+
# if there is an embedded factory(-ies) and we are including the embedded factory's
|
|
166
|
+
# fields, we are going to return a hash
|
|
167
|
+
if include_embeddings
|
|
168
|
+
@attributes.select { |attr| attr.embedded_factories.any? }.each do |attr|
|
|
169
|
+
collection << { attr => attr.embedded_factories.flat_map(&:attributes) }
|
|
170
|
+
end
|
|
171
|
+
# if there is an embedded factory(-ies) and we are not including the embedded factory's
|
|
172
|
+
# fields, just add the attribute into the set of returned fields
|
|
173
|
+
else
|
|
174
|
+
collection |= @attributes.select { |attr| attr.embedded_factories.any? }
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
collection
|
|
117
178
|
end
|
|
118
179
|
|
|
180
|
+
# Finds and returns the first attribute matching the given name.
|
|
181
|
+
#
|
|
182
|
+
# This method searches through the attributes (excluding embeddings) and returns the first attribute
|
|
183
|
+
# whose name, translation, or the result of applying the naming strategy to its name matches the provided `name`.
|
|
184
|
+
#
|
|
185
|
+
# @param name [String] The name to search for among the attributes. Defaults to an empty string.
|
|
186
|
+
# @return [Object, nil] The first matching attribute object, or nil if no match is found.
|
|
119
187
|
def find_attribute( name = '' )
|
|
120
|
-
attributes.filter
|
|
188
|
+
attributes(include_embeddings: false).filter do |a|
|
|
189
|
+
[a.name, a.translation, @naming_strategy&.name(a.name)].include? name
|
|
190
|
+
end.first
|
|
121
191
|
end
|
|
122
192
|
|
|
123
193
|
protected
|
|
124
194
|
|
|
125
|
-
|
|
126
|
-
|
|
195
|
+
# Populates the given instance with attribute values, optionally applying chaos/randomization.
|
|
196
|
+
#
|
|
197
|
+
# @param instance [Object] The object instance to populate with attribute values.
|
|
198
|
+
# @param attr_override_values [Hash] A hash of attribute names and their override values.
|
|
199
|
+
# @param chaos [Boolean, Integer, nil] If truthy, enables chaos mode which may randomize or select a subset of attributes.
|
|
200
|
+
# @return [void]
|
|
201
|
+
#
|
|
202
|
+
# If the factory has a parent, its attributes are populated first.
|
|
203
|
+
# Each attribute is assigned a value, either from the override values or generated.
|
|
204
|
+
# The factory instance is set on the populated object for reference.
|
|
205
|
+
def populate_instance( instance, attr_override_values, chaos: false )
|
|
206
|
+
FakerMaker[parent].populate_instance(instance, attr_override_values, chaos:) if parent?
|
|
127
207
|
|
|
128
208
|
attributes = chaos ? chaos_select(chaos) : @attributes
|
|
129
209
|
|
|
130
210
|
attributes.each do |attribute|
|
|
131
|
-
value = value_for_attribute( instance, attribute, attr_override_values )
|
|
211
|
+
value = value_for_attribute( instance, attribute, attr_override_values, chaos: )
|
|
132
212
|
instance.send "#{attribute.name}=", value
|
|
133
213
|
end
|
|
134
214
|
instance.instance_variable_set( :@fm_factory, self )
|
|
@@ -137,7 +217,10 @@ module FakerMaker
|
|
|
137
217
|
private
|
|
138
218
|
|
|
139
219
|
def assert_only_known_attributes_for_override( attr_override_values )
|
|
140
|
-
unknown_attrs = attr_override_values.keys - attribute_names
|
|
220
|
+
unknown_attrs = attr_override_values.keys - attribute_names.flat_map do |item|
|
|
221
|
+
item.is_a?(Hash) ? item.keys : item
|
|
222
|
+
end
|
|
223
|
+
|
|
141
224
|
issue = "Can't build an instance of '#{class_name}' " \
|
|
142
225
|
"setting '#{unknown_attrs.join( ', ' )}', no such attribute(s)"
|
|
143
226
|
raise FakerMaker::NoSuchAttributeError, issue unless unknown_attrs.empty?
|
|
@@ -156,34 +239,44 @@ module FakerMaker
|
|
|
156
239
|
raise FakerMaker::ChaosConflictingAttributeError, issue unless conflicting_attributes.empty?
|
|
157
240
|
end
|
|
158
241
|
|
|
159
|
-
def
|
|
242
|
+
def overridden_value?( attr, attr_override_values )
|
|
160
243
|
attr_override_values.keys.include?( attr.name )
|
|
161
244
|
end
|
|
162
245
|
|
|
163
|
-
def value_for_attribute( instance, attr, attr_override_values )
|
|
164
|
-
if
|
|
246
|
+
def value_for_attribute( instance, attr, attr_override_values, chaos: false )
|
|
247
|
+
if !attr.embedded_factories? && overridden_value?( attr, attr_override_values )
|
|
165
248
|
attr_override_values[attr.name]
|
|
166
249
|
elsif attr.array?
|
|
167
250
|
[].tap do |a|
|
|
168
251
|
attr.cardinality.times do
|
|
169
|
-
manufacture = manufacture_from_embedded_factory( attr )
|
|
170
|
-
# if manufacture has been
|
|
252
|
+
manufacture = manufacture_from_embedded_factory( attr, attr_override_values[attr.name.to_sym], chaos: )
|
|
253
|
+
# if manufacture has been built and there is a block, instance_exec the block
|
|
171
254
|
# otherwise just add the manufacture to the array
|
|
172
255
|
a << (attr.block ? instance.instance_exec(manufacture, &attr.block) : manufacture)
|
|
173
256
|
end
|
|
174
257
|
end
|
|
175
258
|
else
|
|
176
|
-
manufacture = manufacture_from_embedded_factory( attr )
|
|
259
|
+
manufacture = manufacture_from_embedded_factory( attr, attr_override_values[attr.name.to_sym], chaos: )
|
|
177
260
|
attr.block ? instance.instance_exec(manufacture, &attr.block) : manufacture
|
|
178
261
|
end
|
|
179
262
|
end
|
|
180
263
|
|
|
181
|
-
def manufacture_from_embedded_factory( attr )
|
|
264
|
+
def manufacture_from_embedded_factory( attr, attributes = {}, chaos: false )
|
|
265
|
+
attributes ||= {}
|
|
182
266
|
# The name of the embedded factory randomly selected from the list of embedded factories.
|
|
183
|
-
|
|
267
|
+
embedded_factory = attr.embedded_factories.sample
|
|
268
|
+
|
|
269
|
+
# filter out attributes for non-chosen embedded factories to avoid triggering
|
|
270
|
+
# the NoSuchAttribute exception
|
|
271
|
+
attributes = attr
|
|
272
|
+
.embedded_factories
|
|
273
|
+
.reject { |e| e == embedded_factory }
|
|
274
|
+
.flat_map { |f| pp f.attributes.map(&:name) }
|
|
275
|
+
.then { |excl| attributes.delete_if { |k, _v| excl.include?(k) } }
|
|
276
|
+
|
|
184
277
|
# The object that is being manufactured by the factory.
|
|
185
278
|
# If an embedded factory name is provided, it builds the object using FakerMaker.
|
|
186
|
-
|
|
279
|
+
embedded_factory&.build(attributes:, chaos:)
|
|
187
280
|
end
|
|
188
281
|
|
|
189
282
|
def instantiate
|
|
@@ -264,13 +357,6 @@ module FakerMaker
|
|
|
264
357
|
.concat(selected_attrs).uniq!
|
|
265
358
|
@chaos_selected_attributes
|
|
266
359
|
end
|
|
267
|
-
|
|
268
|
-
def validate_deprecated_build(kwargs)
|
|
269
|
-
usage = kwargs.each_with_object([]) { |kwarg, result| result << "#{kwarg.first}: #{kwarg.last}" }.join(', ')
|
|
270
|
-
|
|
271
|
-
warn "[DEPRECATION] `FM[:#{name}].build(#{usage})` is deprecated. " \
|
|
272
|
-
"Please use `FM[:#{name}].build(attributes: { #{usage} })` instead."
|
|
273
|
-
end
|
|
274
360
|
end
|
|
275
361
|
end
|
|
276
362
|
# rubocop:enable Metrics/ClassLength
|
data/lib/faker_maker/version.rb
CHANGED
data/lib/faker_maker.rb
CHANGED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
---
|
|
2
|
+
permalink: /404.html
|
|
3
|
+
layout: default
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
<style type="text/css" media="screen">
|
|
7
|
+
.container {
|
|
8
|
+
margin: 10px auto;
|
|
9
|
+
max-width: 600px;
|
|
10
|
+
text-align: center;
|
|
11
|
+
}
|
|
12
|
+
h1 {
|
|
13
|
+
margin: 30px 0;
|
|
14
|
+
font-size: 4em;
|
|
15
|
+
line-height: 1;
|
|
16
|
+
letter-spacing: -1px;
|
|
17
|
+
}
|
|
18
|
+
</style>
|
|
19
|
+
|
|
20
|
+
<div class="container">
|
|
21
|
+
<h1>404</h1>
|
|
22
|
+
|
|
23
|
+
<p><strong>Page not found :(</strong></p>
|
|
24
|
+
<p>The requested page could not be found.</p>
|
|
25
|
+
</div>
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
source 'https://rubygems.org'
|
|
4
|
+
# Hello! This is where you manage which Jekyll version is used to run.
|
|
5
|
+
# When you want to use a different version, change it below, save the
|
|
6
|
+
# file and run `bundle install`. Run Jekyll with `bundle exec`, like so:
|
|
7
|
+
#
|
|
8
|
+
# bundle exec jekyll serve
|
|
9
|
+
#
|
|
10
|
+
# This will help ensure the proper Jekyll version is running.
|
|
11
|
+
# Happy Jekylling!
|
|
12
|
+
gem 'jekyll', '~> 4.3.4'
|
|
13
|
+
# This is the default theme for new Jekyll sites. You may change this to anything you like.
|
|
14
|
+
gem 'minima', '~> 2.5'
|
|
15
|
+
# If you want to use GitHub Pages, remove the "gem "jekyll"" above and
|
|
16
|
+
# uncomment the line below. To upgrade, run `bundle update github-pages`.
|
|
17
|
+
# gem "github-pages", group: :jekyll_plugins
|
|
18
|
+
# If you have any plugins, put them here!
|
|
19
|
+
group :jekyll_plugins do
|
|
20
|
+
gem 'jekyll-data'
|
|
21
|
+
gem 'jekyll-feed', '~> 0.12'
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Windows and JRuby does not include zoneinfo files, so bundle the tzinfo-data gem
|
|
25
|
+
# and associated library.
|
|
26
|
+
platforms :mingw, :x64_mingw, :mswin, :jruby do
|
|
27
|
+
gem 'tzinfo', '>= 1', '< 3'
|
|
28
|
+
gem 'tzinfo-data'
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Performance-booster for watching directories on Windows
|
|
32
|
+
gem 'wdm', '~> 0.1', platforms: %i[mingw x64_mingw mswin]
|
|
33
|
+
|
|
34
|
+
# Lock `http_parser.rb` gem to `v0.6.x` on JRuby builds since newer versions of the gem
|
|
35
|
+
# do not have a Java counterpart.
|
|
36
|
+
gem 'base64'
|
|
37
|
+
gem 'csv'
|
|
38
|
+
gem 'http_parser.rb', '~> 0.6.0', platforms: [:jruby]
|
|
39
|
+
gem 'minimal-mistakes-jekyll'
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
This is the Jekyll documentation for Faker Maker.
|
|
2
|
+
|
|
3
|
+
Cloudflare Pages is configurated to automatically deploy the `main` branch of this repository to the `usefakermaker.com` domain.
|
|
4
|
+
|
|
5
|
+
When adding pages, you usually want to add to the `usage` collection. Remember to update the `data/_navigation.yml` file to include the new page in the navigation.
|