tdc 0.3.7 → 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: b38de678846606fd9e8563342d256585f38ff34a0cc4f969a3e5275e8d2c4d7e
4
- data.tar.gz: f6158ca091edf735897be992e53b6d106eac7d0de863725fa2fd65eab1f4ddf8
3
+ metadata.gz: 2887adedbcb323e7d03e75b65538c2afc1edbe5f4ea84c0555e50dda77bc1305
4
+ data.tar.gz: a8be475b6e7edcd72ab2047cab59a198e984b921d4893ca5bac25ef0476540ea
5
5
  SHA512:
6
- metadata.gz: d88d2c5bf021d945861c2e26ebc1336fdc9ae418cd74b01ef7135f8c9edcfbf7cb29dfe9dbd99b834d7a13572338cd6bd5587bb8a08baf6e1ed39a9db3ce8691
7
- data.tar.gz: e30dfc82648765df615d1853861f48c7f204aea8ae375b1fcd48127fba4853fa316c216cc41cfcb2766bd2bf9b7a4cdc83e500909a0ad6656e96237db22f1353
6
+ metadata.gz: f1aaaf060b8e5b85ab96487279471521b9a04738a63cf360473905a6834d08bfc3bd3ddef01c5b2e571736b87177b74a21ee5cba24860e56bcdb206e208e3962
7
+ data.tar.gz: dc9cd3002213b1b5c2f6d95f09b986249c30fe239a28e788f06462d00f496b02a3cbc707d5236bd987d44ea435e9b516adbb777f480cce24a0ca22a06b59fe52
@@ -6,15 +6,26 @@ 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
+
9
20
  ## [0.3.7] - 2020-08-10
10
21
 
11
22
  #### New Features
12
23
 
13
- - Register a context with the AtxContextFactory
24
+ - Register a context with the `AtxContextFactory`
14
25
 
15
26
  ## [0.3.6.1] - 2020-08-10
16
27
 
17
- - Add the AtxContextFactory abstraction
28
+ - Add the `AtxContextFactory` abstraction
18
29
 
19
30
  ## [0.3.6] - 2020-08-06
20
31
 
data/README.md CHANGED
@@ -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,13 +30,10 @@ require "tdc/with_indifferent_access_decorator"
19
30
 
20
31
  # Generators
21
32
  require "tdc/generators"
22
- require "tdc/generators/atx_context_factory"
23
- require "tdc/generators/generation_context"
24
-
25
- # Current Catalog
26
33
  require "tdc/generators/catalog_entries"
34
+ require "tdc/generators/generation_context"
27
35
 
28
- # Concerns
36
+ # Generator Concerns
29
37
  require "tdc/generators/definition_resolvable"
30
38
  require "tdc/generators/definition_sourcable"
31
39
 
@@ -34,11 +42,6 @@ require "tdc/generators/generator_base"
34
42
  require "tdc/generators/configurable_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
  #
@@ -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
@@ -11,7 +11,7 @@ module Tdc
11
11
  source_definition_from :instance_definition
12
12
 
13
13
  def run_resolvers_and_generate_instance
14
- run_atx_resolvers(instance_definition)
14
+ run_extended_attribute_interpreters(instance_definition)
15
15
  run_definition_resolvers(instance_definition)
16
16
 
17
17
  generate_instance
@@ -39,20 +39,12 @@ module Tdc
39
39
  configure_definition_source(instance_definition)
40
40
  end
41
41
 
42
- def run_atx_resolvers(instance_definition)
43
- atx_definitions = instance_definition.select { |k, _v| /_atx$/ =~ k }
44
-
45
- atx_definitions.each do |k, v|
46
- # Remove the original _atx attribute.
47
- instance_definition.delete(k)
48
-
49
- # Add a standard _at attribute.
50
- instance_definition[k.delete_suffix("x")] = atx_context.instance_eval(v)
51
- end
42
+ def run_extended_attribute_interpreters(instance_definition)
43
+ interpreters.each { |interpreter| interpreter.interpret(instance_definition) }
52
44
  end
53
45
 
54
- def atx_context
55
- Tdc::Generators::AtxContextFactory.instance.context
46
+ def interpreters
47
+ Tdc::ExtendedAttributes::InterpreterRegistry.instance.interpreters
56
48
  end
57
49
  end
58
50
  end
@@ -1,3 +1,3 @@
1
1
  module Tdc
2
- VERSION = "0.3.7"
2
+ VERSION = "0.3.8"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tdc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.7
4
+ version: 0.3.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alistair McKinnell
@@ -131,9 +131,12 @@ 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
- - lib/tdc/generators/atx_context_factory.rb
137
140
  - lib/tdc/generators/catalog_entries.rb
138
141
  - lib/tdc/generators/configurable_generator.rb
139
142
  - lib/tdc/generators/definition_resolvable.rb
@@ -1,20 +0,0 @@
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