faker_maker 1.2.0 → 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: '085b4651f6fd8681a1544f7fcc1c3ec05709f2709c701268c16efaf09b4ce06d'
4
- data.tar.gz: bdabf0075d7453c39a24554c659e859781c15b1fc7880b5115134e38438fe756
3
+ metadata.gz: 6355e061188d88ab10d97dae93595abccbf2a73346b6220c265c9241198f93ba
4
+ data.tar.gz: 487700e0d8e88f4fb69d00796bb4d644263e7c91af91eea188caa7eaf82861c5
5
5
  SHA512:
6
- metadata.gz: 19b799c28b8409657e9f8abe28eaaa6dabf6caefc66055e894c843994a9a8b1f66aedc35a356a0da5e620bd8d12cd25dc5cf077393e4dea80f17b9d1cb048c48
7
- data.tar.gz: 3a288478c6afff7c15a3246bc445fcad61a93679fbe345503bcb782d254eb08ea72a825b794699dfb18dad7a1b0522ee5d6a5beb24452b476bd8f365a6449c67
6
+ metadata.gz: e2e50d6ffa61e8164163d2157a65d8a3b93b24e442028e0e04951b25f8e298693bd3a8c6ff3ff948442c38c972f427ec05017020dd120b0cfeefdbb02ebd82b8
7
+ data.tar.gz: 4c1ae45972c019f0929b1c0337b20ebe4f92ecaa040811f515934d50ce38e826956c994a3043d1f8a27928921930a32980d4bff29fceffbb0c8a7a82f1d4ebd6
@@ -0,0 +1,7 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: bundler
4
+ directory: "/"
5
+ schedule:
6
+ interval: daily
7
+ open-pull-requests-limit: 10
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,20 +41,18 @@ 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'
48
48
  spec.add_development_dependency 'guard', '~> 2.16'
49
- spec.add_development_dependency 'guard-bundler', '~> 2.2'
49
+ spec.add_development_dependency 'guard-bundler', '~> 3.0'
50
50
  spec.add_development_dependency 'guard-rubocop', '~> 1.3'
51
51
  spec.add_development_dependency 'guard-rspec', '~> 4.7'
52
52
  spec.add_development_dependency 'pry', '~> 0.12'
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]
@@ -34,7 +34,7 @@ module FakerMaker
34
34
  def omit?( value )
35
35
  case value
36
36
  when nil
37
- @omit.include? :nil
37
+ @omit.include?( :nil ) || @omit.include?( nil )
38
38
  when '', [], {}
39
39
  @omit.include? :empty
40
40
  else
@@ -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
 
@@ -103,7 +105,7 @@ module FakerMaker
103
105
  end
104
106
 
105
107
  def find_attribute( name = '' )
106
- attributes.filter { |a| [a.name, a.translation, @naming_strategy&.name(name)].include? name }.first
108
+ attributes.filter { |a| [a.name, a.translation, @naming_strategy&.name(a.name)].include? name }.first
107
109
  end
108
110
 
109
111
  protected
@@ -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.0'
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.0
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-04-14 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
@@ -78,14 +78,14 @@ dependencies:
78
78
  requirements:
79
79
  - - "~>"
80
80
  - !ruby/object:Gem::Version
81
- version: '2.2'
81
+ version: '3.0'
82
82
  type: :development
83
83
  prerelease: false
84
84
  version_requirements: !ruby/object:Gem::Requirement
85
85
  requirements:
86
86
  - - "~>"
87
87
  - !ruby/object:Gem::Version
88
- version: '2.2'
88
+ version: '3.0'
89
89
  - !ruby/object:Gem::Dependency
90
90
  name: guard-rubocop
91
91
  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,7 @@ executables: []
206
178
  extensions: []
207
179
  extra_rdoc_files: []
208
180
  files:
209
- - ".circleci/config.yml"
210
- - ".coveralls.yml"
181
+ - ".github/dependabot.yml"
211
182
  - ".gitignore"
212
183
  - ".rspec"
213
184
  - ".rubocop.yml"
@@ -229,6 +200,7 @@ files:
229
200
  - docs/installation.md
230
201
  - docs/logo.png
231
202
  - docs/usage/arrays.md
203
+ - docs/usage/audit_logs.md
232
204
  - docs/usage/building_instances.md
233
205
  - docs/usage/dependencies.md
234
206
  - docs/usage/destroying_factories.md
@@ -242,7 +214,9 @@ files:
242
214
  - img/unipug.svg
243
215
  - lib/faker_maker.rb
244
216
  - lib/faker_maker/attribute.rb
217
+ - lib/faker_maker/auditable.rb
245
218
  - lib/faker_maker/base.rb
219
+ - lib/faker_maker/configuration.rb
246
220
  - lib/faker_maker/definition_proxy.rb
247
221
  - lib/faker_maker/factory.rb
248
222
  - lib/faker_maker/lifecycle_hooks.rb
@@ -265,14 +239,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
265
239
  requirements:
266
240
  - - ">="
267
241
  - !ruby/object:Gem::Version
268
- version: '2.6'
242
+ version: '3.0'
269
243
  required_rubygems_version: !ruby/object:Gem::Requirement
270
244
  requirements:
271
245
  - - ">="
272
246
  - !ruby/object:Gem::Version
273
247
  version: '0'
274
248
  requirements: []
275
- rubygems_version: 3.1.4
249
+ rubygems_version: 3.4.10
276
250
  signing_key:
277
251
  specification_version: 4
278
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