tdc 0.3.3 → 0.3.7

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: e58c0fcfbfa32aa0dde6627786e39bbfaff4140d3326f144925113031163faf8
4
- data.tar.gz: e9b5f186a199bd2cc3479fd9fd48087fd0f1d433006c03f2502c2cb48c6f300d
3
+ metadata.gz: b38de678846606fd9e8563342d256585f38ff34a0cc4f969a3e5275e8d2c4d7e
4
+ data.tar.gz: f6158ca091edf735897be992e53b6d106eac7d0de863725fa2fd65eab1f4ddf8
5
5
  SHA512:
6
- metadata.gz: 10a3a536987b80e57169defc47b65496550fc3c9ba4fa91d9c6ec448b8debd77d24d44cf5dbe047d708979fd4d29e4b1186ef712d0cfcb0b094cd0418d6d2524
7
- data.tar.gz: cfd63f4adcb438992e71a4e9ac8c20024c9b1f0d68d4a8eda5765456cb7054c602a3b7f97178f66f5c5e0876314180fd42404c7100d29382d544834e2239f010
6
+ metadata.gz: d88d2c5bf021d945861c2e26ebc1336fdc9ae418cd74b01ef7135f8c9edcfbf7cb29dfe9dbd99b834d7a13572338cd6bd5587bb8a08baf6e1ed39a9db3ce8691
7
+ data.tar.gz: e30dfc82648765df615d1853861f48c7f204aea8ae375b1fcd48127fba4853fa316c216cc41cfcb2766bd2bf9b7a4cdc83e500909a0ad6656e96237db22f1353
@@ -2,39 +2,19 @@ require:
2
2
  - rubocop-rspec
3
3
 
4
4
  AllCops:
5
- TargetRubyVersion: 2.5
5
+ NewCops: enable
6
+ TargetRubyVersion: 2.6
6
7
 
7
8
  Exclude:
8
9
  - 'bin/**/*'
9
10
 
10
- Layout/EmptyLinesAroundAttributeAccessor:
11
- Enabled: true
12
-
13
- Metrics/LineLength:
11
+ Layout/LineLength:
14
12
  Max: 120
15
13
 
16
14
  # Rubocop and I cannot agree.
17
15
  Layout/MultilineMethodCallBraceLayout:
18
16
  Enabled: false
19
17
 
20
- Layout/SpaceAroundMethodCallOperator:
21
- Enabled: true
22
-
23
- Lint/DeprecatedOpenSSLConstant:
24
- Enabled: true
25
-
26
- Lint/DuplicateElsifCondition:
27
- Enabled: true
28
-
29
- Lint/MixedRegexpCaptureTypes:
30
- Enabled: true
31
-
32
- Lint/RaiseException:
33
- Enabled: true
34
-
35
- Lint/StructNewOverride:
36
- Enabled: true
37
-
38
18
  Metrics/BlockLength:
39
19
  Enabled: false
40
20
 
@@ -68,15 +48,6 @@ RSpec/MultipleExpectations:
68
48
  RSpec/SubjectStub:
69
49
  Enabled: false
70
50
 
71
- Style/AccessorGrouping:
72
- Enabled: true
73
-
74
- Style/ArrayCoercion:
75
- Enabled: true
76
-
77
- Style/BisectedAttrAccessor:
78
- Enabled: true
79
-
80
51
  Style/BlockDelimiters:
81
52
  Enabled: true
82
53
  EnforcedStyle: line_count_based
@@ -84,56 +55,24 @@ Style/BlockDelimiters:
84
55
  - 'let'
85
56
  - 'subject'
86
57
 
87
- Style/CaseLikeIf:
88
- Enabled: true
89
-
90
58
  Style/Documentation:
91
59
  Enabled: false
92
60
 
93
61
  Style/EmptyMethod:
94
62
  EnforcedStyle: expanded
95
63
 
96
- Style/ExponentialNotation:
97
- Enabled: true
98
-
99
64
  # We can ignore this small performance improvement.
100
65
  Style/FrozenStringLiteralComment:
101
66
  Enabled: false
102
67
 
103
- Style/HashAsLastArrayItem:
104
- Enabled: true
105
-
106
- Style/HashEachMethods:
107
- Enabled: true
108
-
109
- Style/HashLikeCase:
110
- Enabled: true
111
-
112
- Style/HashTransformKeys:
113
- Enabled: true
114
-
115
- Style/HashTransformValues:
116
- Enabled: true
117
-
118
68
  # We like to use the hash rocket in rake files.
119
69
  Style/HashSyntax:
120
70
  Exclude:
121
71
  - 'Rakefile'
122
72
 
123
- Style/RedundantAssignment:
124
- Enabled: true
125
-
126
- Style/RedundantFetchBlock:
127
- Enabled: true
128
-
129
- Style/RedundantFileExtensionInRequire:
130
- Enabled: true
131
-
132
- Style/RedundantRegexpCharacterClass:
133
- Enabled: true
134
-
135
- Style/RedundantRegexpEscape:
136
- Enabled: true
73
+ # We are not going to optimize by freezing strings.
74
+ Style/MutableConstant:
75
+ Enabled: false
137
76
 
138
77
  # No need to mention StandardError.
139
78
  Style/RescueStandardError:
@@ -150,6 +89,6 @@ Style/StringLiterals:
150
89
  Style/SymbolArray:
151
90
  Enabled: false
152
91
 
153
- # We are not going to optimize by freezing strings.
154
- Style/MutableConstant:
92
+ # I prefer not to use %w or %W for an array of words.
93
+ Style/WordArray:
155
94
  Enabled: false
@@ -6,6 +6,37 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.3.7] - 2020-08-10
10
+
11
+ #### New Features
12
+
13
+ - Register a context with the AtxContextFactory
14
+
15
+ ## [0.3.6.1] - 2020-08-10
16
+
17
+ - Add the AtxContextFactory abstraction
18
+
19
+ ## [0.3.6] - 2020-08-06
20
+
21
+ #### Breaking Changes
22
+
23
+ - Drop the `SingularGenerator` abstraction
24
+
25
+ ## [0.3.5] - 2020-08-06
26
+
27
+ - Add the `single_entry` method to `CatalogEntries`
28
+
29
+ #### Breaking Changes
30
+
31
+ - Drop the `with_definition` method from `SingularGenerator`
32
+
33
+ ## [0.3.4] - 2020-08-05
34
+
35
+ #### Breaking Changes
36
+
37
+ - Introduce the `GenerationContext` abstraction
38
+ - All generators are initialized with an instance of `Tdc::Generators::GenerationContext`
39
+
9
40
  ## [0.3.3] - 2020-08-04
10
41
 
11
42
  - Add the `empty?` method to `CatalogEntries`
@@ -55,5 +86,3 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
55
86
  #### New Features
56
87
 
57
88
  - Avoid all PackManager dependencies
58
-
59
-
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  **Extension Points**
6
6
 
7
- Define your own test data generators by inheriting from ```StandardGenerator``` or ```SingularGenerator```. Best practice is to define an ```ApplicationStandardGenerator``` and an ```ApplicationSingularGenerator``` and have all other generators inherit from them.
7
+ Define your own test data generators by inheriting from ```StandardGenerator```. Best practice is to define an ```ApplicationStandardGenerator``` and have all other generators inherit from it.
8
8
 
9
9
  Define your own definition resolvers by inheriting from ```DefinitionResolver```. Best practice is to define an ```ApplicationDefinitionResolver``` and all other definition resolvers inherit from it.
10
10
 
Binary file
data/lib/tdc.rb CHANGED
@@ -19,6 +19,8 @@ require "tdc/with_indifferent_access_decorator"
19
19
 
20
20
  # Generators
21
21
  require "tdc/generators"
22
+ require "tdc/generators/atx_context_factory"
23
+ require "tdc/generators/generation_context"
22
24
 
23
25
  # Current Catalog
24
26
  require "tdc/generators/catalog_entries"
@@ -30,7 +32,6 @@ require "tdc/generators/definition_sourcable"
30
32
  # Generator Hierarchy
31
33
  require "tdc/generators/generator_base"
32
34
  require "tdc/generators/configurable_generator"
33
- require "tdc/generators/singular_generator"
34
35
  require "tdc/generators/standard_generator"
35
36
 
36
37
  # Definition Resolvers
@@ -6,6 +6,8 @@ module Tdc
6
6
  EMPTY_DEFINITIONS = []
7
7
 
8
8
  def initialize(catalog_root_directory)
9
+ super()
10
+
9
11
  @catalog_root_directory = catalog_root_directory
10
12
  end
11
13
 
@@ -8,6 +8,8 @@ module Tdc
8
8
  attr_reader :key, :source
9
9
 
10
10
  def initialize(key:, source:)
11
+ super()
12
+
11
13
  @key = key
12
14
  @source = source
13
15
  end
@@ -0,0 +1,20 @@
1
+ module Tdc
2
+ module Generators
3
+ #
4
+ # Knows a class instance that supplies the instance_eval context for interpreting _atx attribute values.
5
+ #
6
+ class AtxContextFactory
7
+ include Singleton
8
+
9
+ attr_reader :context
10
+
11
+ def self.register(context:)
12
+ AtxContextFactory.instance.instance_variable_set(:@context, context)
13
+ end
14
+
15
+ def initialize
16
+ @context = Time.zone
17
+ end
18
+ end
19
+ end
20
+ end
@@ -12,6 +12,12 @@ module Tdc
12
12
  def empty?
13
13
  to_h.empty?
14
14
  end
15
+
16
+ def single_entry
17
+ raise Tdc::FatalError, "There is more than one entry" if to_h.many?
18
+
19
+ to_h.first.second
20
+ end
15
21
  end
16
22
  end
17
23
  end
@@ -3,8 +3,6 @@ module Tdc
3
3
  #
4
4
  # Knows how to provide a configurable instance definition.
5
5
  #
6
- # Shared implementation between the StandardGenerator and the SingularGenerator abstract classes.
7
- #
8
6
  class ConfigurableGenerator < Tdc::Generators::GeneratorBase
9
7
  include Tdc::Generators::DefinitionSourcable
10
8
 
@@ -44,9 +42,6 @@ module Tdc
44
42
  def run_atx_resolvers(instance_definition)
45
43
  atx_definitions = instance_definition.select { |k, _v| /_atx$/ =~ k }
46
44
 
47
- # ARM (2020-08-04): Move all the way out so that all generators use the same atx_context.
48
- atx_context = Time.zone
49
-
50
45
  atx_definitions.each do |k, v|
51
46
  # Remove the original _atx attribute.
52
47
  instance_definition.delete(k)
@@ -55,6 +50,10 @@ module Tdc
55
50
  instance_definition[k.delete_suffix("x")] = atx_context.instance_eval(v)
56
51
  end
57
52
  end
53
+
54
+ def atx_context
55
+ Tdc::Generators::AtxContextFactory.instance.context
56
+ end
58
57
  end
59
58
  end
60
59
  end
@@ -38,7 +38,7 @@ module Tdc
38
38
  definition_source&.key?(key) ? definition_source.fetch(key) : super
39
39
  end
40
40
 
41
- def respond_to_missing?(method, include_all = false)
41
+ def respond_to_missing?(method, include_all = false) # rubocop:disable Style/OptionalBooleanParameter
42
42
  key = transform_method_to_definition_source_key(method)
43
43
 
44
44
  definition_source&.key?(key) ? true : super
@@ -0,0 +1,15 @@
1
+ module Tdc
2
+ module Generators
3
+ #
4
+ # Knows all the parameters that define the context for generation.
5
+ #
6
+ class GenerationContext
7
+ attr_reader :current_catalog, :data_definition
8
+
9
+ def initialize(current_catalog:, data_definition:)
10
+ @current_catalog = current_catalog
11
+ @data_definition = data_definition
12
+ end
13
+ end
14
+ end
15
+ end
@@ -4,11 +4,13 @@ module Tdc
4
4
  # Abstract base class for all Test Data Catalog generators.
5
5
  #
6
6
  class GeneratorBase
7
- attr_reader :data_definition, :current_catalog
7
+ attr_reader :generation_context
8
8
 
9
- def initialize(data_definition, current_catalog)
10
- @data_definition = data_definition
11
- @current_catalog = current_catalog
9
+ # ARM (2020-08-05): For backwards compatibility. Consider removing.
10
+ delegate :current_catalog, :data_definition, to: :generation_context
11
+
12
+ def initialize(generation_context)
13
+ @generation_context = generation_context
12
14
  end
13
15
 
14
16
  def generate
@@ -4,6 +4,8 @@ module Tdc
4
4
  #
5
5
  class InMemoryDataDefinition < Tdc::DataDefinition
6
6
  def initialize(path_elements_data = {})
7
+ super()
8
+
7
9
  @store = path_elements_data
8
10
  end
9
11
 
@@ -1,3 +1,3 @@
1
1
  module Tdc
2
- VERSION = "0.3.3"
2
+ VERSION = "0.3.7"
3
3
  end
@@ -32,7 +32,7 @@ Gem::Specification.new do |spec|
32
32
 
33
33
  spec.add_development_dependency "rake", ">= 12.1", "< 13.1"
34
34
  spec.add_development_dependency "rspec", ">= 3.9", "< 4.0"
35
- spec.add_development_dependency "rubocop", "~> 0.88"
35
+ spec.add_development_dependency "rubocop", "~> 0.89"
36
36
  spec.add_development_dependency "rubocop-rspec", "~> 1.42"
37
37
  spec.add_development_dependency "simplecov", "~> 0.17"
38
38
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tdc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alistair McKinnell
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-08-04 00:00:00.000000000 Z
11
+ date: 2020-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -70,14 +70,14 @@ dependencies:
70
70
  requirements:
71
71
  - - "~>"
72
72
  - !ruby/object:Gem::Version
73
- version: '0.88'
73
+ version: '0.89'
74
74
  type: :development
75
75
  prerelease: false
76
76
  version_requirements: !ruby/object:Gem::Requirement
77
77
  requirements:
78
78
  - - "~>"
79
79
  - !ruby/object:Gem::Version
80
- version: '0.88'
80
+ version: '0.89'
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: rubocop-rspec
83
83
  requirement: !ruby/object:Gem::Requirement
@@ -133,12 +133,13 @@ files:
133
133
  - lib/tdc/definition_resolvers/tag_resolver.rb
134
134
  - lib/tdc/fatal_error.rb
135
135
  - lib/tdc/generators.rb
136
+ - lib/tdc/generators/atx_context_factory.rb
136
137
  - lib/tdc/generators/catalog_entries.rb
137
138
  - lib/tdc/generators/configurable_generator.rb
138
139
  - lib/tdc/generators/definition_resolvable.rb
139
140
  - lib/tdc/generators/definition_sourcable.rb
141
+ - lib/tdc/generators/generation_context.rb
140
142
  - lib/tdc/generators/generator_base.rb
141
- - lib/tdc/generators/singular_generator.rb
142
143
  - lib/tdc/generators/standard_generator.rb
143
144
  - lib/tdc/in_memory_data_definition.rb
144
145
  - lib/tdc/missing_override_error.rb
@@ -1,39 +0,0 @@
1
- module Tdc
2
- module Generators
3
- #
4
- # Abstract class for defining generators that define a single model instance.
5
- #
6
- # See also StandardGenerator.
7
- #
8
- class SingularGenerator < Tdc::Generators::ConfigurableGenerator
9
- def with_definition(additional_definitions)
10
- @additional_definitions = additional_definitions.stringify_keys.reject { |_, v| v == :missing_definition }
11
-
12
- self
13
- end
14
-
15
- def generate
16
- configure_instance_definition(singular_instance_definition.merge(additional_definitions))
17
-
18
- run_resolvers_and_generate_instance
19
- end
20
-
21
- private
22
-
23
- def additional_definitions
24
- @additional_definitions || {}
25
- end
26
-
27
- def singular_instance_definition
28
- all_instance_definitions = instance_definitions
29
-
30
- if all_instance_definitions.many?
31
- raise Tdc::FatalError, "A singular generator only generates a single model instance"
32
- end
33
-
34
- # Delete the tag so that the models do not need to filter it out.
35
- all_instance_definitions.first.except("tag")
36
- end
37
- end
38
- end
39
- end