faker_maker 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/faker_maker/attribute.rb +1 -1
- data/lib/faker_maker/factory.rb +13 -6
- data/lib/faker_maker/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2ec69f6145d624d4c97304fc347e0968000490eed3330bd6821757d8e91709b
|
4
|
+
data.tar.gz: c0def7a4f1f467c0c0a5cf7cba89eac31673ee9d9a75cbd21bc781bf1e3049bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 89c0415112f57426f32515643829fde4191a3017b8934154fca010d5447302b56f0b5ab6f9467257646d22c5a9c40e4983f805c77502fdcd87a93f420c4bb28f
|
7
|
+
data.tar.gz: d2cf75a2cc0cc2d038df826d4ebfc53e192c62547e9167bae13894c179c8e20c7068fc9f4503cfb704cd116e70a844e82db9b93d57b82111681eedd617d63b42
|
@@ -6,7 +6,7 @@ module FakerMaker
|
|
6
6
|
def initialize( name, block = nil, options = {} )
|
7
7
|
assert_valid_options options
|
8
8
|
@name = name
|
9
|
-
@block = block
|
9
|
+
@block = block || proc { nil }
|
10
10
|
@cardinality = options[:has] || 1
|
11
11
|
@translation = options[:json]
|
12
12
|
@array = options[:array] == true
|
data/lib/faker_maker/factory.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# rubocop:disable Metrics/ClassLength
|
1
2
|
module FakerMaker
|
2
3
|
# Factories construct instances of a fake
|
3
4
|
class Factory
|
@@ -26,6 +27,7 @@ module FakerMaker
|
|
26
27
|
|
27
28
|
def build( attributes = {} )
|
28
29
|
instance = instantiate
|
30
|
+
assert_only_known_attributes_for_override( attributes )
|
29
31
|
populate_instance instance, attributes
|
30
32
|
yield instance if block_given?
|
31
33
|
instance
|
@@ -61,23 +63,27 @@ module FakerMaker
|
|
61
63
|
@json_key_map
|
62
64
|
end
|
63
65
|
|
66
|
+
def attribute_names( collection = [] )
|
67
|
+
collection |= FakerMaker[parent].attribute_names( collection ) if parent?
|
68
|
+
collection | attributes.map( &:name )
|
69
|
+
end
|
70
|
+
|
64
71
|
protected
|
65
72
|
|
66
|
-
def populate_instance( instance, attr_override_values )
|
67
|
-
assert_only_known_attributes_for_override( attr_override_values )
|
68
|
-
|
73
|
+
def populate_instance( instance, attr_override_values )
|
69
74
|
FakerMaker[parent].populate_instance instance, attr_override_values if parent?
|
70
|
-
@attributes.each do |attr|
|
75
|
+
@attributes.each do |attr|
|
71
76
|
value = value_for_attribute( instance, attr, attr_override_values )
|
72
77
|
instance.send "#{attr.name}=", value
|
73
78
|
end
|
74
79
|
instance.instance_variable_set( :@fm_factory, self )
|
75
80
|
end
|
76
|
-
|
81
|
+
|
82
|
+
|
77
83
|
private
|
78
84
|
|
79
85
|
def assert_only_known_attributes_for_override( attr_override_values )
|
80
|
-
unknown_attrs = attr_override_values.keys -
|
86
|
+
unknown_attrs = attr_override_values.keys - attribute_names
|
81
87
|
issue = "Can't build an instance of '#{class_name}' " \
|
82
88
|
"setting '#{unknown_attrs.join( ', ' )}', no such attribute(s)"
|
83
89
|
raise FakerMaker::NoSuchAttributeError, issue unless unknown_attrs.empty?
|
@@ -119,3 +125,4 @@ module FakerMaker
|
|
119
125
|
end
|
120
126
|
end
|
121
127
|
end
|
128
|
+
# rubocop:enable Metrics/ClassLength
|
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.1.
|
4
|
+
version: 1.1.2
|
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-07-
|
11
|
+
date: 2019-07-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|