tdc 0.3.4 → 0.3.8

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: bf0ce48e5dd1a629ad0c5240f9c3d8c344b46cf368e01bb842eefb3454167b4e
4
- data.tar.gz: a85d7fef856826f3a4a4112c4e4186c1e813f8a52de500466ba0b9acfe559fe5
3
+ metadata.gz: 2887adedbcb323e7d03e75b65538c2afc1edbe5f4ea84c0555e50dda77bc1305
4
+ data.tar.gz: a8be475b6e7edcd72ab2047cab59a198e984b921d4893ca5bac25ef0476540ea
5
5
  SHA512:
6
- metadata.gz: 250b3ebace2728d87756a51f7075c3f318637997e5473bb90c4cccd820326f77ebf00429e57e885467d837b969c166b43f5044d75b028022f0dcd1464f7967bd
7
- data.tar.gz: 8082f7dbdcd16c0a7cacb94af1479d0df9e4a12a83ec57556f0e6a865e18d5a5d7fa4d14cc2e3e8c3886c2ae2373bf64733e138072f262b1efc27e89ea259798
6
+ metadata.gz: f1aaaf060b8e5b85ab96487279471521b9a04738a63cf360473905a6834d08bfc3bd3ddef01c5b2e571736b87177b74a21ee5cba24860e56bcdb206e208e3962
7
+ data.tar.gz: dc9cd3002213b1b5c2f6d95f09b986249c30fe239a28e788f06462d00f496b02a3cbc707d5236bd987d44ea435e9b516adbb777f480cce24a0ca22a06b59fe52
@@ -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,12 +6,47 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.3.8] - 2020-08-11
10
+
11
+ #### New Features
12
+
13
+ - Multiple subclass instances of `ExtendedAttributes::InterpreterBase` may be registered
14
+ - A default extended attribute interpreter recognizes `_atx`, `_datex`, or `_onx` date/time attributes
15
+
16
+ #### Breaking Changes
17
+
18
+ - Rename `AtxContextFactory` to `ExtendedAttributes::InterpreterRegistry`
19
+
20
+ ## [0.3.7] - 2020-08-10
21
+
22
+ #### New Features
23
+
24
+ - Register a context with the `AtxContextFactory`
25
+
26
+ ## [0.3.6.1] - 2020-08-10
27
+
28
+ - Add the `AtxContextFactory` abstraction
29
+
30
+ ## [0.3.6] - 2020-08-06
31
+
32
+ #### Breaking Changes
33
+
34
+ - Drop the `SingularGenerator` abstraction
35
+
36
+ ## [0.3.5] - 2020-08-06
37
+
38
+ - Add the `single_entry` method to `CatalogEntries`
39
+
40
+ #### Breaking Changes
41
+
42
+ - Drop the `with_definition` method from `SingularGenerator`
43
+
9
44
  ## [0.3.4] - 2020-08-05
10
45
 
11
46
  #### Breaking Changes
12
47
 
13
48
  - Introduce the `GenerationContext` abstraction
14
- - All generators are initialized with an instance of `Tdc::GenerationContext`
49
+ - All generators are initialized with an instance of `Tdc::Generators::GenerationContext`
15
50
 
16
51
  ## [0.3.3] - 2020-08-04
17
52
 
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
 
@@ -13,3 +13,5 @@ During generation the test data catalog will be represented by ```CatalogEntries
13
13
  **Data Definition DSL**
14
14
 
15
15
  ```DefinitionResolvable``` and ```DefinitionSourcable``` provide a DSL that you may use in your generators to work more easily with a ```DataDefinition```.
16
+
17
+ By registering a class instance that inherits from ```ExtendedAttributes::InterpreterBase``` with the ```ExtendedAttributes::InterpreterRegistry``` you may extend the DSL that is used to interpret attribute values.
Binary file
data/lib/tdc.rb CHANGED
@@ -7,10 +7,21 @@ require "active_support/core_ext"
7
7
 
8
8
  require "tdc/version"
9
9
 
10
- # Errors
10
+ # Definition Resolvers
11
+ require "tdc/definition_resolvers"
12
+ require "tdc/definition_resolvers/definition_resolver"
13
+ require "tdc/definition_resolvers/tag_resolver"
14
+
15
+ # Tdc Errors
11
16
  require "tdc/fatal_error"
12
17
  require "tdc/missing_override_error"
13
18
 
19
+ # Extended Attributes
20
+ require "tdc/extended_attributes"
21
+ require "tdc/extended_attributes/interpreter_base"
22
+ require "tdc/extended_attributes/default_interpreter"
23
+ require "tdc/extended_attributes/interpreter_registry"
24
+
14
25
  # Data Definition Hierarchy
15
26
  require "tdc/data_definition"
16
27
  require "tdc/data_definition_file_reader"
@@ -19,26 +30,18 @@ require "tdc/with_indifferent_access_decorator"
19
30
 
20
31
  # Generators
21
32
  require "tdc/generators"
22
- require "tdc/generators/generation_context"
23
-
24
- # Current Catalog
25
33
  require "tdc/generators/catalog_entries"
34
+ require "tdc/generators/generation_context"
26
35
 
27
- # Concerns
36
+ # Generator Concerns
28
37
  require "tdc/generators/definition_resolvable"
29
38
  require "tdc/generators/definition_sourcable"
30
39
 
31
40
  # Generator Hierarchy
32
41
  require "tdc/generators/generator_base"
33
42
  require "tdc/generators/configurable_generator"
34
- require "tdc/generators/singular_generator"
35
43
  require "tdc/generators/standard_generator"
36
44
 
37
- # Definition Resolvers
38
- require "tdc/definition_resolvers"
39
- require "tdc/definition_resolvers/definition_resolver"
40
- require "tdc/definition_resolvers/tag_resolver"
41
-
42
45
  #
43
46
  # A framework for building a Test Data Catalog
44
47
  #
@@ -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,7 @@
1
+ module Tdc
2
+ #
3
+ # Namespace to host extended attributes.
4
+ #
5
+ module ExtendedAttributes
6
+ end
7
+ end
@@ -0,0 +1,31 @@
1
+ module Tdc
2
+ module ExtendedAttributes
3
+ class DefaultInterpreter < Tdc::ExtendedAttributes::InterpreterBase
4
+ def interpret(instance_definition)
5
+ extended_attribute_definitions = keep_extended_attributes(instance_definition)
6
+
7
+ extended_attribute_definitions.each do |k, v|
8
+ # Remove the original extended attribute.
9
+ instance_definition.delete(k)
10
+
11
+ # Add a standard attribute.
12
+ instance_definition[convert_to_standard_attribute(k)] = extended_attribute_context.instance_eval(v)
13
+ end
14
+ end
15
+
16
+ concerning :HookMethods do
17
+ def convert_to_standard_attribute(k) # rubocop:disable Naming/MethodParameterName
18
+ k.delete_suffix("x")
19
+ end
20
+
21
+ def extended_attribute_context
22
+ Time.zone
23
+ end
24
+
25
+ def keep_extended_attributes(instance_definition)
26
+ instance_definition.select { |k, _v| /_(at|date|on)x$/ =~ k }
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,9 @@
1
+ module Tdc
2
+ module ExtendedAttributes
3
+ class InterpreterBase
4
+ def interpret(_instance_definition)
5
+ raise Tdc::MissingOverrideError, "Implement the 'keep_extended_attributes' method"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,32 @@
1
+ module Tdc
2
+ module ExtendedAttributes
3
+ #
4
+ # Knows the class instances that interpret extended attribute values.
5
+ #
6
+ class InterpreterRegistry
7
+ include Singleton
8
+
9
+ def self.register(interpreter:)
10
+ instance.register_interpreter(interpreter)
11
+ end
12
+
13
+ def initialize
14
+ @interpreters = []
15
+ end
16
+
17
+ def interpreters
18
+ @interpreters << Tdc::ExtendedAttributes::DefaultInterpreter.new if @interpreters.empty?
19
+
20
+ @interpreters
21
+ end
22
+
23
+ def register_interpreter(interpreter)
24
+ raise Tdc::FatalError, <<~MSG unless interpreter.is_a?(Tdc::ExtendedAttributes::InterpreterBase)
25
+ Cannot register an interpreter unless it inherits from Tdc::ExtendedAttributes::InterpreterBase
26
+ MSG
27
+
28
+ @interpreters << interpreter
29
+ end
30
+ end
31
+ end
32
+ 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
 
@@ -13,7 +11,7 @@ module Tdc
13
11
  source_definition_from :instance_definition
14
12
 
15
13
  def run_resolvers_and_generate_instance
16
- run_atx_resolvers(instance_definition)
14
+ run_extended_attribute_interpreters(instance_definition)
17
15
  run_definition_resolvers(instance_definition)
18
16
 
19
17
  generate_instance
@@ -41,19 +39,12 @@ module Tdc
41
39
  configure_definition_source(instance_definition)
42
40
  end
43
41
 
44
- def run_atx_resolvers(instance_definition)
45
- atx_definitions = instance_definition.select { |k, _v| /_atx$/ =~ k }
46
-
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
- atx_definitions.each do |k, v|
51
- # Remove the original _atx attribute.
52
- instance_definition.delete(k)
42
+ def run_extended_attribute_interpreters(instance_definition)
43
+ interpreters.each { |interpreter| interpreter.interpret(instance_definition) }
44
+ end
53
45
 
54
- # Add a standard _at attribute.
55
- instance_definition[k.delete_suffix("x")] = atx_context.instance_eval(v)
56
- end
46
+ def interpreters
47
+ Tdc::ExtendedAttributes::InterpreterRegistry.instance.interpreters
57
48
  end
58
49
  end
59
50
  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
@@ -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.4"
2
+ VERSION = "0.3.8"
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.4
4
+ version: 0.3.8
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-05 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
@@ -131,6 +131,10 @@ files:
131
131
  - lib/tdc/definition_resolvers.rb
132
132
  - lib/tdc/definition_resolvers/definition_resolver.rb
133
133
  - lib/tdc/definition_resolvers/tag_resolver.rb
134
+ - lib/tdc/extended_attributes.rb
135
+ - lib/tdc/extended_attributes/default_interpreter.rb
136
+ - lib/tdc/extended_attributes/interpreter_base.rb
137
+ - lib/tdc/extended_attributes/interpreter_registry.rb
134
138
  - lib/tdc/fatal_error.rb
135
139
  - lib/tdc/generators.rb
136
140
  - lib/tdc/generators/catalog_entries.rb
@@ -139,7 +143,6 @@ files:
139
143
  - lib/tdc/generators/definition_sourcable.rb
140
144
  - lib/tdc/generators/generation_context.rb
141
145
  - lib/tdc/generators/generator_base.rb
142
- - lib/tdc/generators/singular_generator.rb
143
146
  - lib/tdc/generators/standard_generator.rb
144
147
  - lib/tdc/in_memory_data_definition.rb
145
148
  - 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