faker_maker 1.2.1 → 1.3.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: 7d52a9450058657ec1fba8756afa5a965a6f92fcf074ef5d05c0c2b7a1d09ea2
4
- data.tar.gz: e0c12b011abd0337a5699a054c44e0b4fc3eb05f385b24a0dd9e54d2864ee611
3
+ metadata.gz: 6355e061188d88ab10d97dae93595abccbf2a73346b6220c265c9241198f93ba
4
+ data.tar.gz: 487700e0d8e88f4fb69d00796bb4d644263e7c91af91eea188caa7eaf82861c5
5
5
  SHA512:
6
- metadata.gz: d467cdafe73e4ddd1cf0b1677f96c935f28430b09b2580b7a141d674d4c8690f6c850bacb8c2f2c22ad32805e9d2d2e8c86c77f5807a50018d375299f56c70b1
7
- data.tar.gz: 4f4ede5c6ac0e3290952e29f03b90855c7112332a32a6ceaebe0d5b8ab54340388698bebcdaadabe390beb55a4ac91597200a8960e668e8fb9f0a276ad9f00e1
6
+ metadata.gz: e2e50d6ffa61e8164163d2157a65d8a3b93b24e442028e0e04951b25f8e298693bd3a8c6ff3ff948442c38c972f427ec05017020dd120b0cfeefdbb02ebd82b8
7
+ data.tar.gz: 4c1ae45972c019f0929b1c0337b20ebe4f92ecaa040811f515934d50ce38e826956c994a3043d1f8a27928921930a32980d4bff29fceffbb0c8a7a82f1d4ebd6
data/.rubocop.yml CHANGED
@@ -43,4 +43,7 @@ Metrics/MethodLength:
43
43
  Enabled: false
44
44
 
45
45
  Lint/MissingSuper:
46
- Enabled: false
46
+ Enabled: false
47
+
48
+ AllCops:
49
+ NewCops: enable
data/Guardfile CHANGED
@@ -17,7 +17,7 @@
17
17
  #
18
18
  # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
19
19
 
20
- # Note: The cmd option is now required due to the increasing number of ways
20
+ # NOTE: The cmd option is now required due to the increasing number of ways
21
21
  # rspec may be run, below are examples of the most common uses.
22
22
  # * bundler: 'bundle exec rspec'
23
23
  # * bundler binstubs: 'bin/rspec'
@@ -0,0 +1,47 @@
1
+ ---
2
+ layout: default
3
+ title: Audit (History) Logs
4
+ parent: Usage
5
+ nav_order: 10
6
+ ---
7
+
8
+ _(since 1.3.0)_
9
+
10
+ # Audit logs
11
+
12
+ It might be useful to collect the history of all the fakes generated by your factories. FakerMaker allows you to stream (or write to a file) all the instances it builds for you. This is optional and disabled by default.
13
+
14
+ ## Enable logging
15
+
16
+ By default audit logging is disabled. The default output stream is `STDOUT`. The output target can either be an object that responds to `puts`, or be a string which will be interpreted as a file location to use to write to. If file path string is used, it will be opened in 'append' mode.
17
+
18
+ ```ruby
19
+ FakerMaker.configure do |config|
20
+ config.audit = true
21
+ config.audit_destination = '/tmp/faker_maker_audit_logs'
22
+ end
23
+ ```
24
+
25
+ ## Audit streams
26
+
27
+ Immediately after each object is built and after the post-build hooks have completed, the instance details will be logged in line-delimited JSON (JSONL), to the stream or file. Each line is contained in an envelope containing the following metadata:
28
+
29
+ * The timestamp at the time of logging
30
+ * The name of factory
31
+ * The class name of the object the factory instantiated
32
+
33
+ For example, given the factory:
34
+
35
+ ```ruby
36
+ FakerMaker.factory :user do
37
+ name {'Patsy Stone'}
38
+ email {'patsy@fabulous.co.uk'}
39
+ admin {false}
40
+ end
41
+ ```
42
+
43
+ The audit log, on build, would look like:
44
+
45
+ ```
46
+ {"timestamp":"2023-05-15T15:46:30+01:00","factory":"user","class":"User","body":{"name":"Patsy Stone","email":"patsy@fabulous.co.uk","admin":false}}
47
+ ```
data/faker_maker.gemspec CHANGED
@@ -41,7 +41,7 @@ Gem::Specification.new do |spec|
41
41
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
42
42
  spec.require_paths = ['lib']
43
43
 
44
- spec.add_dependency 'activesupport', '>= 5.2', '< 7'
44
+ spec.add_dependency 'activesupport', '>= 5.2', '< 8'
45
45
 
46
46
  spec.add_development_dependency 'bundler', '~> 2.0'
47
47
  spec.add_development_dependency 'faker', '~> 2.1'
@@ -53,8 +53,6 @@ Gem::Specification.new do |spec|
53
53
  spec.add_development_dependency 'rake', '~> 13.0'
54
54
  spec.add_development_dependency 'rspec', '~> 3.8'
55
55
  spec.add_development_dependency 'rubocop', '~> 1.0'
56
- spec.add_development_dependency 'simplecov', '~> 0.16'
57
- spec.add_development_dependency 'coveralls', '~> 0.8'
58
56
 
59
- spec.required_ruby_version = '>= 2.6'
57
+ spec.required_ruby_version = '>= 3.0'
60
58
  end
@@ -8,7 +8,7 @@ module FakerMaker
8
8
  def initialize( name, block = nil, options = {} )
9
9
  assert_valid_options options
10
10
  @name = name
11
- @block = block || proc { nil }
11
+ @block = block || proc {}
12
12
  @cardinality = options[:has] || 1
13
13
  @translation = options[:json]
14
14
  @omit = *options[:omit]
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ # FakerMaker module for generating Fakes
4
+ module FakerMaker
5
+ # Mix-in module which provides the auditable functionality
6
+ module Auditable
7
+ def audit(instance)
8
+ envelope = audit_envelope(class: instance.class.name, body: instance.as_json)
9
+ audit_stream.puts(JSON.generate(envelope))
10
+ audit_stream.flush if audit_stream.respond_to?(:flush)
11
+ rescue StandardError => e
12
+ warn "FakerMaker Warning: #{e.class}: \"#{e.message}\" occurred. FakerMaker will disable audit logging. " \
13
+ 'Further warnings supressed.'
14
+ FakerMaker.configuration.audit = false
15
+ end
16
+
17
+ private
18
+
19
+ def audit_stream
20
+ destination = FakerMaker.configuration.audit_destination
21
+ return destination if destination.respond_to?(:puts)
22
+
23
+ file_destination = File.new(destination, 'a')
24
+ FakerMaker.configuration.audit_destination = file_destination
25
+ end
26
+
27
+ def audit_envelope(**overrides)
28
+ {
29
+ timestamp: DateTime.now.iso8601,
30
+ factory: name.to_s,
31
+ **overrides
32
+ }
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ # FakerMaker module for generating Fakes
4
+ module FakerMaker
5
+ # Configuration class, holds all the config options for FM
6
+ class Configuration
7
+ attr_writer :audit
8
+ attr_accessor :audit_destination
9
+
10
+ def initialize
11
+ @audit = false
12
+ @audit_destination = $stdout
13
+ end
14
+
15
+ def audit?
16
+ @audit
17
+ end
18
+ end
19
+
20
+ # Mixin to provide configuraton methods to an extending or implementing class
21
+ module Configurable
22
+ def configuration
23
+ @configuration ||= Configuration.new
24
+ end
25
+
26
+ def configuration=(config)
27
+ @configuration = config
28
+ end
29
+
30
+ def configure
31
+ yield(configuration) if block_given?
32
+ end
33
+ end
34
+ end
@@ -4,6 +4,7 @@
4
4
  module FakerMaker
5
5
  # Factories construct instances of a fake
6
6
  class Factory
7
+ include Auditable
7
8
  attr_reader :name, :class_name, :parent
8
9
 
9
10
  def initialize( name, options = {} )
@@ -48,6 +49,7 @@ module FakerMaker
48
49
  populate_instance instance, attributes
49
50
  yield instance if block_given?
50
51
  after_build if respond_to? :after_build
52
+ audit(@instance) if FakerMaker.configuration.audit?
51
53
  instance
52
54
  end
53
55
 
@@ -4,12 +4,12 @@ module FakerMaker
4
4
  module LifecycleHooks
5
5
  # Lifecycle hooks which can be called during the building of an instance
6
6
  module DefinitionProxy
7
- def before_build(&block)
8
- @factory.define_singleton_method(:before_build) { yield(self.instance, self) }
7
+ def before_build
8
+ @factory.define_singleton_method(:before_build) { yield(instance, self) }
9
9
  end
10
10
 
11
- def after_build(&block)
12
- @factory.define_singleton_method(:after_build) { yield(self.instance, self) }
11
+ def after_build
12
+ @factory.define_singleton_method(:after_build) { yield(instance, self) }
13
13
  end
14
14
  end
15
15
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FakerMaker
4
- VERSION = '1.2.1'
4
+ VERSION = '1.3.0'
5
5
  end
data/lib/faker_maker.rb CHANGED
@@ -1,11 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'time'
4
+
3
5
  require 'active_support'
4
6
  require 'active_support/core_ext/hash'
5
7
  require 'active_support/core_ext/object/json'
6
8
  require 'active_support/core_ext/string'
7
9
  require 'faker_maker/attribute'
10
+ require 'faker_maker/auditable'
8
11
  require 'faker_maker/base'
12
+ require 'faker_maker/configuration'
9
13
  require 'faker_maker/lifecycle_hooks'
10
14
  require 'faker_maker/definition_proxy'
11
15
  require 'faker_maker/factory'
@@ -18,6 +22,7 @@ require 'faker_maker/version'
18
22
  # FakerMaker module for generating Fakes
19
23
  module FakerMaker
20
24
  extend FakerMaker::Base
25
+ extend FakerMaker::Configurable
21
26
 
22
27
  class Error < StandardError; end
23
28
  class NoSuchFactoryError < StandardError; 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.2.1
4
+ version: 1.3.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: 2021-11-16 00:00:00.000000000 Z
11
+ date: 2023-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '5.2'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '7'
22
+ version: '8'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: '5.2'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '7'
32
+ version: '8'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: bundler
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -170,34 +170,6 @@ dependencies:
170
170
  - - "~>"
171
171
  - !ruby/object:Gem::Version
172
172
  version: '1.0'
173
- - !ruby/object:Gem::Dependency
174
- name: simplecov
175
- requirement: !ruby/object:Gem::Requirement
176
- requirements:
177
- - - "~>"
178
- - !ruby/object:Gem::Version
179
- version: '0.16'
180
- type: :development
181
- prerelease: false
182
- version_requirements: !ruby/object:Gem::Requirement
183
- requirements:
184
- - - "~>"
185
- - !ruby/object:Gem::Version
186
- version: '0.16'
187
- - !ruby/object:Gem::Dependency
188
- name: coveralls
189
- requirement: !ruby/object:Gem::Requirement
190
- requirements:
191
- - - "~>"
192
- - !ruby/object:Gem::Version
193
- version: '0.8'
194
- type: :development
195
- prerelease: false
196
- version_requirements: !ruby/object:Gem::Requirement
197
- requirements:
198
- - - "~>"
199
- - !ruby/object:Gem::Version
200
- version: '0.8'
201
173
  description: FakerMaker is a simple factory builder so you can throw away your fixtures
202
174
  and generate test data instead.
203
175
  email:
@@ -206,8 +178,6 @@ executables: []
206
178
  extensions: []
207
179
  extra_rdoc_files: []
208
180
  files:
209
- - ".circleci/config.yml"
210
- - ".coveralls.yml"
211
181
  - ".github/dependabot.yml"
212
182
  - ".gitignore"
213
183
  - ".rspec"
@@ -230,6 +200,7 @@ files:
230
200
  - docs/installation.md
231
201
  - docs/logo.png
232
202
  - docs/usage/arrays.md
203
+ - docs/usage/audit_logs.md
233
204
  - docs/usage/building_instances.md
234
205
  - docs/usage/dependencies.md
235
206
  - docs/usage/destroying_factories.md
@@ -243,7 +214,9 @@ files:
243
214
  - img/unipug.svg
244
215
  - lib/faker_maker.rb
245
216
  - lib/faker_maker/attribute.rb
217
+ - lib/faker_maker/auditable.rb
246
218
  - lib/faker_maker/base.rb
219
+ - lib/faker_maker/configuration.rb
247
220
  - lib/faker_maker/definition_proxy.rb
248
221
  - lib/faker_maker/factory.rb
249
222
  - lib/faker_maker/lifecycle_hooks.rb
@@ -266,14 +239,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
266
239
  requirements:
267
240
  - - ">="
268
241
  - !ruby/object:Gem::Version
269
- version: '2.6'
242
+ version: '3.0'
270
243
  required_rubygems_version: !ruby/object:Gem::Requirement
271
244
  requirements:
272
245
  - - ">="
273
246
  - !ruby/object:Gem::Version
274
247
  version: '0'
275
248
  requirements: []
276
- rubygems_version: 3.2.22
249
+ rubygems_version: 3.4.10
277
250
  signing_key:
278
251
  specification_version: 4
279
252
  summary: FakerMaker bakes fakes.
data/.circleci/config.yml DELETED
@@ -1,13 +0,0 @@
1
- # Use the latest 2.1 version of CircleCI pipeline processing engine, see https://circleci.com/docs/2.0/configuration-reference/
2
- version: 2.1
3
-
4
- jobs:
5
- build:
6
- docker:
7
- - image: circleci/ruby:2.6.3-stretch-node
8
- steps:
9
- - checkout
10
- - run: gem update --system
11
- - run: gem install bundler
12
- - run: bundle install
13
- - run: bundle exec rake spec
data/.coveralls.yml DELETED
@@ -1 +0,0 @@
1
- repo_token: K7czIqoKhrE9BRBk1ubEToyJkLgTk0frJ