faker_maker 1.1.1 → 1.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1c59c0553af51e24cdb8c40eaf37fb1913546c17ab47df37a1a52b5c16ffe9ee
4
- data.tar.gz: 2035e5c27455309c20e0ecdf500917720612bacd3abc32ad573f45a9568676c6
3
+ metadata.gz: c2ec69f6145d624d4c97304fc347e0968000490eed3330bd6821757d8e91709b
4
+ data.tar.gz: c0def7a4f1f467c0c0a5cf7cba89eac31673ee9d9a75cbd21bc781bf1e3049bc
5
5
  SHA512:
6
- metadata.gz: f83f89e5d405e335a0df45027f721e8b650635eef537dc79e068fcb6841a452abe6a1ca9e13db74b22e8805adfa870bf4c066ff5096d7a84edf84c5ff5e62199
7
- data.tar.gz: 054545cad0cd1e0023eb3306bcbfbcd0b054b7a8b6734c192d1090d5f4d8b5aee6288872a51b7df6cb6b67746652111c40b0da9b35c68c97a319b10f68441010
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
@@ -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 - @attributes.map( &:name )
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
@@ -1,3 +1,3 @@
1
1
  module FakerMaker
2
- VERSION = '1.1.1'.freeze
2
+ VERSION = '1.1.2'.freeze
3
3
  end
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.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-08 00:00:00.000000000 Z
11
+ date: 2019-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport