tdc 0.2.4 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +2 -0
- data/images/Tdc.png +0 -0
- data/lib/tdc.rb +5 -0
- data/lib/tdc/definition_resolvers.rb +7 -0
- data/lib/tdc/definition_resolvers/definition_resolver.rb +18 -0
- data/lib/tdc/definition_resolvers/tag_resolver.rb +38 -0
- data/lib/tdc/generators.rb +1 -1
- data/lib/tdc/generators/configurable_generator.rb +2 -2
- data/lib/tdc/generators/definition_resolvable.rb +33 -35
- data/lib/tdc/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6d7775cd9909b7d1aef1f59def823777cc24d6bbfc50ddfd41eda202f5f5f387
|
4
|
+
data.tar.gz: 11b7ddadec9d97e1953f34efdee8b66d6f0cb08213dd8d9a9e9d4ae8372687fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f396da321ee096251062cd35ff6add1d19292591dc8fa019509fe432f2fd7faea74844ee4583fbb30bc03e9f8106fbeabdb403732ec5098d70c40b69e2c216c
|
7
|
+
data.tar.gz: 69cfdaa1a302ae2d458f6775db22134953db4f6f584ba9af36970f4865d308de9a44d9c5c6ec10e7db0a4ec5c05d340254a4458dfc843d6676225459e2542660
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [0.3.0] - 2020-07-19
|
10
|
+
|
11
|
+
- Introduce the DefinitionResolver abstraction
|
12
|
+
|
9
13
|
## [0.2.4] - 2020-07-19
|
10
14
|
|
11
15
|
- Improve Tdc::MissingOverrideError diagnostics
|
data/README.md
CHANGED
@@ -6,6 +6,8 @@
|
|
6
6
|
|
7
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.
|
8
8
|
|
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
|
+
|
9
11
|
During generation the test data catalog will be represented by ```CatalogEntries``` that are populated by reading from ```YAML``` files with a ```DataDefinitionReader``` or provided directly by an ```InMemoryDataDefinition```.
|
10
12
|
|
11
13
|
**Data Definition DSL**
|
data/images/Tdc.png
CHANGED
Binary file
|
data/lib/tdc.rb
CHANGED
@@ -33,6 +33,11 @@ require "tdc/generators/configurable_generator"
|
|
33
33
|
require "tdc/generators/singular_generator"
|
34
34
|
require "tdc/generators/standard_generator"
|
35
35
|
|
36
|
+
# Definition Resolvers
|
37
|
+
require "tdc/definition_resolvers"
|
38
|
+
require "tdc/definition_resolvers/definition_resolver"
|
39
|
+
require "tdc/definition_resolvers/tag_resolver"
|
40
|
+
|
36
41
|
#
|
37
42
|
# A framework for building a Test Data Catalog
|
38
43
|
#
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Tdc
|
2
|
+
module DefinitionResolvers
|
3
|
+
#
|
4
|
+
# Base class for any definition resolver.
|
5
|
+
#
|
6
|
+
class DefinitionResolver
|
7
|
+
attr_reader :current_catalog
|
8
|
+
|
9
|
+
def configure_current_catalog(current_catalog)
|
10
|
+
@current_catalog = current_catalog
|
11
|
+
end
|
12
|
+
|
13
|
+
def resolve(_instance_definition)
|
14
|
+
raise Tdc::MissingOverrideError, "Implement the 'resolve' method"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Tdc
|
2
|
+
module DefinitionResolvers
|
3
|
+
#
|
4
|
+
# Knows how to resolve the tag value for the specified instance_definition key by replacing it
|
5
|
+
# with an object sourced from the current catalog.
|
6
|
+
#
|
7
|
+
class TagResolver < Tdc::DefinitionResolvers::DefinitionResolver
|
8
|
+
attr_reader :key, :source
|
9
|
+
|
10
|
+
def initialize(key:, source:)
|
11
|
+
@key = key
|
12
|
+
@source = source
|
13
|
+
end
|
14
|
+
|
15
|
+
def resolve(instance_definition)
|
16
|
+
return unless instance_definition.key?(key)
|
17
|
+
|
18
|
+
# Lookup the source catalog entry in the current_catalog.
|
19
|
+
catalog_entry = instance_eval("current_catalog.#{source}", __FILE__, __LINE__)
|
20
|
+
|
21
|
+
# Before resolution the instance definition value is a tag.
|
22
|
+
tag = instance_definition[key]
|
23
|
+
|
24
|
+
# Use the tag to source an object from the current catalog.
|
25
|
+
sourced_object = catalog_entry.send(tag)
|
26
|
+
|
27
|
+
unless sourced_object
|
28
|
+
message = "Could not find a tag reference for '#{key}' in the catalog entries provided."
|
29
|
+
|
30
|
+
raise Tdc::FatalError, message
|
31
|
+
end
|
32
|
+
|
33
|
+
# Replace the tag value with the sourced object.
|
34
|
+
instance_definition[key] = sourced_object
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/tdc/generators.rb
CHANGED
@@ -14,7 +14,7 @@ module Tdc
|
|
14
14
|
|
15
15
|
def run_resolvers_and_generate_instance
|
16
16
|
run_atx_resolvers(instance_definition)
|
17
|
-
|
17
|
+
run_definition_resolvers(instance_definition)
|
18
18
|
|
19
19
|
generate_instance
|
20
20
|
end
|
@@ -29,7 +29,7 @@ module Tdc
|
|
29
29
|
#
|
30
30
|
# Hook method: subclasses may include the DefinitionResolvable concern to override.
|
31
31
|
#
|
32
|
-
def
|
32
|
+
def run_definition_resolvers(_instance_definition)
|
33
33
|
# Do nothing
|
34
34
|
end
|
35
35
|
|
@@ -1,61 +1,59 @@
|
|
1
1
|
module Tdc
|
2
2
|
module Generators
|
3
3
|
#
|
4
|
-
# Knows how to resolve
|
5
|
-
#
|
4
|
+
# Knows how to resolve attribute values in an instance definition. The attribute value will be replaced
|
5
|
+
# by the result of invoking the specified resolver.
|
6
6
|
#
|
7
|
-
# The resolve_tag class macro is provided for generators to define tag resolution.
|
7
|
+
# The resolve_tag class macro is provided for generators to define tag resolution. The test data definition
|
8
|
+
# YAML file has attribute values than contain a catalog entry tag.
|
8
9
|
#
|
9
10
|
# Example:
|
10
11
|
#
|
11
|
-
# Suppose a particular instance definition contained { subcomponent: sc_snackers_minis }
|
12
|
-
#
|
12
|
+
# Suppose a particular instance definition contained { subcomponent: sc_snackers_minis } then a generator
|
13
|
+
# could resolve the subcomponent tag to the current catalog by defining:
|
13
14
|
#
|
14
15
|
# resolve_tag key: :subcomponent, source: "item_master.items"
|
15
16
|
#
|
17
|
+
# The resolve_definition class macro is provided for generators to define definition resolution. The test data
|
18
|
+
# definition YAML file has attribute values than contain an arbitrary value that will typically be replaced by
|
19
|
+
# an instance of an object returned by the specified resolver.
|
20
|
+
#
|
21
|
+
# Example:
|
22
|
+
#
|
23
|
+
# Suppose a particular instance definition contained { pallet_number: P0001 } then a generator could resolve
|
24
|
+
# the pallet_number to a pallet instance by defining:
|
25
|
+
#
|
26
|
+
# resolve_definition :pallet_number, to: :pallet_id, resolver: "TestDataCatalog::Resolvers::PalletNumberResolver"
|
27
|
+
#
|
28
|
+
# The PalletNumberResolver class inherits from Tdc::DefinitionResolvers::DefinitionResolver.
|
29
|
+
#
|
16
30
|
module DefinitionResolvable
|
17
31
|
extend ActiveSupport::Concern
|
18
32
|
|
19
33
|
included do
|
20
|
-
class_attribute :
|
21
|
-
|
34
|
+
class_attribute :_definition_resolvers, instance_writer: false
|
35
|
+
|
36
|
+
self._definition_resolvers = []
|
22
37
|
end
|
23
38
|
|
24
39
|
class_methods do
|
25
|
-
def
|
26
|
-
|
40
|
+
def resolve_definition(key:, to: nil, resolver:)
|
41
|
+
resolver_instance = resolver.constantize.new(key: key, to: to || key)
|
42
|
+
|
43
|
+
_definition_resolvers << resolver_instance
|
27
44
|
end
|
28
|
-
end
|
29
45
|
|
30
|
-
|
31
|
-
|
46
|
+
def resolve_tag(key:, source:)
|
47
|
+
_definition_resolvers << Tdc::DefinitionResolvers::TagResolver.new(key: key, source: source)
|
48
|
+
end
|
32
49
|
end
|
33
50
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
# Replace the tag value for the specified instance_definition key with an object sourced from the current catalog.
|
38
|
-
#
|
39
|
-
def _resolve_tag_reference(instance_definition, key, source)
|
40
|
-
return unless instance_definition.key?(key)
|
41
|
-
|
42
|
-
# Lookup the source catalog entry in the current_catalog.
|
43
|
-
catalog_entry = instance_eval("current_catalog.#{source}", __FILE__, __LINE__)
|
51
|
+
def run_definition_resolvers(instance_definition)
|
52
|
+
_definition_resolvers.each do |definition_resolver|
|
53
|
+
definition_resolver.configure_current_catalog(current_catalog)
|
44
54
|
|
45
|
-
|
46
|
-
tag = instance_definition[key]
|
47
|
-
|
48
|
-
# Use the tag to source an object from the current catalog.
|
49
|
-
sourced_object = catalog_entry.send(tag)
|
50
|
-
|
51
|
-
unless sourced_object
|
52
|
-
message = "Could not find a tag reference for '#{key}' in the catalog entries provided."
|
53
|
-
|
54
|
-
raise Tdc::FatalError, message
|
55
|
+
definition_resolver.resolve(instance_definition)
|
55
56
|
end
|
56
|
-
|
57
|
-
# Replace the tag value with the sourced object.
|
58
|
-
instance_definition[key] = sourced_object
|
59
57
|
end
|
60
58
|
end
|
61
59
|
end
|
data/lib/tdc/version.rb
CHANGED
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.
|
4
|
+
version: 0.3.0
|
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-07-
|
11
|
+
date: 2020-07-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -128,6 +128,9 @@ files:
|
|
128
128
|
- lib/tdc.rb
|
129
129
|
- lib/tdc/data_definition.rb
|
130
130
|
- lib/tdc/data_definition_file_reader.rb
|
131
|
+
- lib/tdc/definition_resolvers.rb
|
132
|
+
- lib/tdc/definition_resolvers/definition_resolver.rb
|
133
|
+
- lib/tdc/definition_resolvers/tag_resolver.rb
|
131
134
|
- lib/tdc/fatal_error.rb
|
132
135
|
- lib/tdc/generators.rb
|
133
136
|
- lib/tdc/generators/catalog_entries.rb
|