faker_maker 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fee4b085d7597c65882a322c750393492922c22653b66bb5c4b2e2da064c85be
4
- data.tar.gz: ad9fa43a58aefcba71b1beaa0a2a53ebbf200644b01f9cfd568f234d665d1631
3
+ metadata.gz: b168e0875afcb5acfddf49f5ffc2732392983b343c9d161e8b773abbb36308e5
4
+ data.tar.gz: f2be17a2fa07b32f41e53034a6512eac0a6b7e4268d39b0e66ad2fa8fb57adb0
5
5
  SHA512:
6
- metadata.gz: 14dd70aa6b4cdac5402e1603073bd018dbd699b23181ef8294c8ea5ec3b759d8e6dc6fffcccec30f66e3b34d764c975e6c899b8703027f94ffbdf4b4e53ae2f5
7
- data.tar.gz: '083a7808d7c4c8d8830b1c02595192f9f72aef08880918d9667e7f63e8d5749f42878f239f24443aa4c680b7f5d6cce8f39b1992be1c50bde782f9b02f4a71ca'
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 assign to the variable `FM` to it is possible to write just:
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
@@ -48,4 +48,5 @@ Gem::Specification.new do |spec|
48
48
  spec.add_development_dependency 'rspec', '~> 3.8'
49
49
  spec.add_development_dependency 'rubocop', '~> 0.68'
50
50
  spec.add_development_dependency 'simplecov', '~> 0.16'
51
+ spec.add_development_dependency 'coveralls', '~> 0.8'
51
52
  end
@@ -64,11 +64,11 @@ module FakerMaker
64
64
  protected
65
65
 
66
66
  def populate_instance( instance, attr_override_values )
67
- assert_only_know_attributes_for_override( attr_override_values )
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 assert_only_know_attributes_for_override( attr_override_values )
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.call
96
+ instance.instance_eval(&attr.block)
97
97
  end
98
98
  end
99
99
 
@@ -1,3 +1,3 @@
1
1
  module FakerMaker
2
- VERSION = '1.0.1'.freeze
2
+ VERSION = '1.1.0'.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.0.1
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-05-10 00:00:00.000000000 Z
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"