faker_maker 1.0.1 → 1.1.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/.coveralls.yml +1 -0
- data/README.md +15 -1
- data/faker_maker.gemspec +1 -0
- data/lib/faker_maker/factory.rb +6 -6
- data/lib/faker_maker/version.rb +1 -1
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b168e0875afcb5acfddf49f5ffc2732392983b343c9d161e8b773abbb36308e5
|
4
|
+
data.tar.gz: f2be17a2fa07b32f41e53034a6512eac0a6b7e4268d39b0e66ad2fa8fb57adb0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b4671f26ee492a62a27a9520b6f1331978c4145568730c98a5a905569b3cc350031c11229102418648ed4be01a020325f339e6ccd4f886cdbe92026a9c38dd0
|
7
|
+
data.tar.gz: 814c3bbe801dae701a28d638a946508c1b025223fbaff899d0c40b6f777d207b383ba1ea58dc1b5daba03bdcea3de29eef323784d60e4d792d08c25f9a5530ac
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
repo_token: K7czIqoKhrE9BRBk1ubEToyJkLgTk0frJ
|
data/README.md
CHANGED
@@ -59,6 +59,18 @@ FakerMaker.factory :response do
|
|
59
59
|
end
|
60
60
|
```
|
61
61
|
|
62
|
+
Blocks are executed in the context of their instance. This means you can refer to variables already defined:
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
FakerMaker.factory :user, class: 'EmailUser' do
|
66
|
+
title {'Ms'}
|
67
|
+
name {'Patsy Stone'}
|
68
|
+
formal_name {"#{title} #{name}"}
|
69
|
+
email {'patsy@fabulous.co.uk'}
|
70
|
+
admin {false}
|
71
|
+
end
|
72
|
+
```
|
73
|
+
|
62
74
|
### Inheritance
|
63
75
|
|
64
76
|
FakerMaker can exploit the Ruby class hierarchy to provide additional specialisation or to override some behaviours:
|
@@ -128,6 +140,8 @@ FakerMaker.factory :basket do
|
|
128
140
|
end
|
129
141
|
```
|
130
142
|
|
143
|
+
### JSON field names
|
144
|
+
|
131
145
|
### Building instances
|
132
146
|
|
133
147
|
Instances are Plain Ol' Ruby Objects and the attributes are attached with getters and setters with their values assigned to the value return from their block at build time.
|
@@ -172,7 +186,7 @@ As a convenience, you can request a JSON representation directly:
|
|
172
186
|
result = FakerMaker[:basket].to_json
|
173
187
|
```
|
174
188
|
|
175
|
-
As another convenience, `FakerMaker` is also
|
189
|
+
As another convenience, `FakerMaker` is also assigned to the variable `FM` to it is possible to write just:
|
176
190
|
|
177
191
|
```ruby
|
178
192
|
result = FM[:basket].build
|
data/faker_maker.gemspec
CHANGED
data/lib/faker_maker/factory.rb
CHANGED
@@ -64,11 +64,11 @@ module FakerMaker
|
|
64
64
|
protected
|
65
65
|
|
66
66
|
def populate_instance( instance, attr_override_values )
|
67
|
-
|
67
|
+
assert_only_known_attributes_for_override( attr_override_values )
|
68
68
|
|
69
|
-
FakerMaker[parent].populate_instance instance if parent?
|
69
|
+
FakerMaker[parent].populate_instance instance, attr_override_values if parent?
|
70
70
|
@attributes.each do |attr|
|
71
|
-
value = value_for_attribute( attr, attr_override_values )
|
71
|
+
value = value_for_attribute( instance, attr, attr_override_values )
|
72
72
|
instance.send "#{attr.name}=", value
|
73
73
|
end
|
74
74
|
instance.instance_variable_set( :@fm_factory, self )
|
@@ -76,7 +76,7 @@ module FakerMaker
|
|
76
76
|
|
77
77
|
private
|
78
78
|
|
79
|
-
def
|
79
|
+
def assert_only_known_attributes_for_override( attr_override_values )
|
80
80
|
unknown_attrs = attr_override_values.keys - @attributes.map( &:name )
|
81
81
|
issue = "Can't build an instance of '#{class_name}' " \
|
82
82
|
"setting '#{unknown_attrs.join( ', ' )}', no such attribute(s)"
|
@@ -87,13 +87,13 @@ module FakerMaker
|
|
87
87
|
!attr_override_values[attr.name].nil?
|
88
88
|
end
|
89
89
|
|
90
|
-
def value_for_attribute( attr, attr_override_values )
|
90
|
+
def value_for_attribute( instance, attr, attr_override_values )
|
91
91
|
if attribute_hash_overridden_value?( attr, attr_override_values )
|
92
92
|
attr_override_values[attr.name]
|
93
93
|
elsif attr.array?
|
94
94
|
[].tap { |a| attr.cardinality.times { a << attr.block.call } }
|
95
95
|
else
|
96
|
-
attr.block
|
96
|
+
instance.instance_eval(&attr.block)
|
97
97
|
end
|
98
98
|
end
|
99
99
|
|
data/lib/faker_maker/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faker_maker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nigel Brookes-Thomas
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-07-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -128,6 +128,20 @@ dependencies:
|
|
128
128
|
- - "~>"
|
129
129
|
- !ruby/object:Gem::Version
|
130
130
|
version: '0.16'
|
131
|
+
- !ruby/object:Gem::Dependency
|
132
|
+
name: coveralls
|
133
|
+
requirement: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - "~>"
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0.8'
|
138
|
+
type: :development
|
139
|
+
prerelease: false
|
140
|
+
version_requirements: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - "~>"
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0.8'
|
131
145
|
description: FakerMaker is a simple fixture generator with a concise and straightforward
|
132
146
|
syntax.
|
133
147
|
email:
|
@@ -137,6 +151,7 @@ extensions: []
|
|
137
151
|
extra_rdoc_files: []
|
138
152
|
files:
|
139
153
|
- ".circleci/config.yml"
|
154
|
+
- ".coveralls.yml"
|
140
155
|
- ".gitignore"
|
141
156
|
- ".rspec"
|
142
157
|
- ".rubocop.yml"
|