tdc 0.4.0 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +8 -0
- data/CHANGELOG.md +22 -0
- data/lib/tdc.rb +8 -0
- data/lib/tdc/data_definition_file_reader.rb +2 -33
- data/lib/tdc/definition_resolvers/tag_resolver.rb +0 -2
- data/lib/tdc/extended_attributes/default_interpreter.rb +27 -11
- data/lib/tdc/extended_attributes/interpreter_registry.rb +8 -4
- data/lib/tdc/generators/catalog_entries.rb +5 -1
- data/lib/tdc/generators/definition_sourcable.rb +18 -8
- data/lib/tdc/in_memory_data_definition.rb +0 -2
- data/lib/tdc/version.rb +1 -1
- data/lib/tdc/yaml_readers.rb +7 -0
- data/lib/tdc/yaml_readers/null_yaml_reader.rb +12 -0
- data/lib/tdc/yaml_readers/yaml_reader.rb +16 -0
- data/lib/tdc/yaml_readers/yaml_reader_base.rb +52 -0
- data/lib/tdc/yaml_readers/yaml_reader_factory.rb +38 -0
- data/lib/tdc/yaml_readers/yaml_reader_with_expansion.rb +16 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9afbee316bed8c63956e2a3f1626e376101940ecbb83e45fc6f7dd699d626df4
|
4
|
+
data.tar.gz: c4f164c51b6421490d157cbf4761ad4d9e634af72a6a52a6bce0443cfd4b32a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd3f18ae6079f57dce2faa700c27ec64c86f266eb54820a2952beeeefcf3d4e8bcb0a785e69b02b222bcfa29f56ad5484c888dcea3d8d74e58610435ac4273e0
|
7
|
+
data.tar.gz: 219c4136fc7dc4717e9c83849d7318cbe05751b661dd9d95bbbaa2cc5a621188a44b13b7e2624c9c80c4126e34ced7274673dabe0af6e62488977cefa26e29ac
|
data/.rubocop.yml
CHANGED
@@ -15,12 +15,20 @@ Layout/LineLength:
|
|
15
15
|
Layout/MultilineMethodCallBraceLayout:
|
16
16
|
Enabled: false
|
17
17
|
|
18
|
+
# Revisit. Seems a little harsh.
|
19
|
+
Lint/MissingSuper:
|
20
|
+
Enabled: false
|
21
|
+
|
18
22
|
Metrics/BlockLength:
|
19
23
|
Enabled: false
|
20
24
|
|
21
25
|
Naming/MemoizedInstanceVariableName:
|
22
26
|
EnforcedStyleForLeadingUnderscores: required
|
23
27
|
|
28
|
+
Naming/VariableNumber:
|
29
|
+
Enabled: true
|
30
|
+
EnforcedStyle: snake_case
|
31
|
+
|
24
32
|
RSpec/AnyInstance:
|
25
33
|
Enabled: false
|
26
34
|
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,28 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [0.4.4] - 2020-08-25
|
10
|
+
|
11
|
+
#### Breaking Changes
|
12
|
+
|
13
|
+
- Enable ERB expansion of the YAML source with a `.yam.erb` filename suffix.
|
14
|
+
|
15
|
+
## [0.4.3] - 2020-08-25
|
16
|
+
|
17
|
+
#### New Features
|
18
|
+
|
19
|
+
- Support optional definitions
|
20
|
+
|
21
|
+
## [0.4.2] - 2020-08-22
|
22
|
+
|
23
|
+
#### Breaking Changes
|
24
|
+
|
25
|
+
- Extended attributes use `_xa` suffix
|
26
|
+
|
27
|
+
## [0.4.1] - 2020-08-22
|
28
|
+
|
29
|
+
- Add the `first` method to `CatalogEntries`
|
30
|
+
|
9
31
|
## [0.4.0] - 2020-08-14
|
10
32
|
|
11
33
|
#### New Features
|
data/lib/tdc.rb
CHANGED
@@ -41,6 +41,14 @@ require "tdc/generators/definition_sourcable"
|
|
41
41
|
require "tdc/generators/generator_base"
|
42
42
|
require "tdc/generators/standard_generator"
|
43
43
|
|
44
|
+
# YAML Readers
|
45
|
+
require "tdc/yaml_readers"
|
46
|
+
require "tdc/yaml_readers/null_yaml_reader"
|
47
|
+
require "tdc/yaml_readers/yaml_reader_base"
|
48
|
+
require "tdc/yaml_readers/yaml_reader"
|
49
|
+
require "tdc/yaml_readers/yaml_reader_with_expansion"
|
50
|
+
require "tdc/yaml_readers/yaml_reader_factory"
|
51
|
+
|
44
52
|
#
|
45
53
|
# A framework for building a Test Data Catalog
|
46
54
|
#
|
@@ -6,44 +6,13 @@ module Tdc
|
|
6
6
|
EMPTY_DEFINITIONS = []
|
7
7
|
|
8
8
|
def initialize(catalog_root_directory)
|
9
|
-
super()
|
10
|
-
|
11
9
|
@catalog_root_directory = catalog_root_directory
|
12
10
|
end
|
13
11
|
|
14
12
|
def read(*path_elements)
|
15
|
-
|
16
|
-
end
|
17
|
-
|
18
|
-
private
|
19
|
-
|
20
|
-
def definitions_file(path_elements)
|
21
|
-
fully_qualified_path_elements = [@catalog_root_directory].concat(path_elements.map(&:to_s))
|
22
|
-
|
23
|
-
fully_qualified_path_elements.last.concat(".yml")
|
24
|
-
|
25
|
-
File.join(*fully_qualified_path_elements)
|
26
|
-
end
|
27
|
-
|
28
|
-
def data_definition_from(definitions_file)
|
29
|
-
if File.exist?(definitions_file)
|
30
|
-
load_yaml(definitions_file) || EMPTY_DEFINITIONS
|
31
|
-
else
|
32
|
-
EMPTY_DEFINITIONS
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def load_yaml(definitions_file)
|
37
|
-
YAML.load(expand_erb(definitions_file)) # rubocop:disable Security/YAMLLoad
|
38
|
-
rescue => e
|
39
|
-
raise Tdc::FatalError, <<~MSG
|
40
|
-
Unable to load YAML from #{definitions_file}
|
41
|
-
Cause: #{e.message}"
|
42
|
-
MSG
|
43
|
-
end
|
13
|
+
reader = Tdc::YamlReaders::YamlReaderFactory.new(@catalog_root_directory, path_elements).create
|
44
14
|
|
45
|
-
|
46
|
-
ERB.new(File.read(definitions_file)).result
|
15
|
+
reader.data_definitions
|
47
16
|
end
|
48
17
|
end
|
49
18
|
end
|
@@ -1,29 +1,45 @@
|
|
1
1
|
module Tdc
|
2
2
|
module ExtendedAttributes
|
3
|
+
#
|
4
|
+
# Know how on interpret extended attributes.
|
5
|
+
#
|
6
|
+
# Note: extended attribute keys are expected to be strings rather than symbols.
|
7
|
+
#
|
3
8
|
class DefaultInterpreter < Tdc::ExtendedAttributes::InterpreterBase
|
4
9
|
def interpret(instance_definition)
|
5
10
|
extended_attribute_definitions = keep_extended_attributes(instance_definition)
|
6
11
|
|
7
|
-
extended_attribute_definitions.each do |
|
8
|
-
# Remove the
|
9
|
-
instance_definition.delete(
|
12
|
+
extended_attribute_definitions.each do |extended_attribute_key, extended_attribute_value|
|
13
|
+
# Remove the extended attribute.
|
14
|
+
instance_definition.delete(extended_attribute_key)
|
10
15
|
|
11
|
-
# Add a standard attribute.
|
12
|
-
instance_definition[convert_to_standard_attribute(
|
16
|
+
# Add the extended attribute back as a standard attribute.
|
17
|
+
instance_definition[convert_to_standard_attribute(extended_attribute_key)] =
|
18
|
+
extended_attribute_context.instance_eval(extended_attribute_value)
|
13
19
|
end
|
14
20
|
end
|
15
21
|
|
16
22
|
concerning :HookMethods do
|
17
|
-
def convert_to_standard_attribute(k) # rubocop:disable Naming/MethodParameterName
|
18
|
-
k.delete_suffix("x")
|
19
|
-
end
|
20
|
-
|
21
23
|
def extended_attribute_context
|
22
24
|
Time.zone
|
23
25
|
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
EXTENDED_ATTRIBUTE_SUFFIX = "_xa"
|
31
|
+
|
32
|
+
def convert_to_standard_attribute(extended_attribute_key)
|
33
|
+
extended_attribute_key.delete_suffix(EXTENDED_ATTRIBUTE_SUFFIX)
|
34
|
+
end
|
35
|
+
|
36
|
+
def extended_attribute?(extended_attribute_key)
|
37
|
+
extended_attribute_key.end_with?(EXTENDED_ATTRIBUTE_SUFFIX)
|
38
|
+
end
|
24
39
|
|
25
|
-
|
26
|
-
|
40
|
+
def keep_extended_attributes(instance_definition)
|
41
|
+
instance_definition.select do |extended_attribute_key, _|
|
42
|
+
extended_attribute?(extended_attribute_key)
|
27
43
|
end
|
28
44
|
end
|
29
45
|
end
|
@@ -15,18 +15,22 @@ module Tdc
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def interpreters
|
18
|
-
@interpreters
|
19
|
-
|
20
|
-
@interpreters
|
18
|
+
@interpreters.empty? ? [default_interpreter] : @interpreters
|
21
19
|
end
|
22
20
|
|
23
21
|
def register_interpreter(interpreter)
|
24
|
-
raise Tdc::FatalError, <<~MSG unless interpreter.is_a?(Tdc::ExtendedAttributes::InterpreterBase)
|
22
|
+
raise Tdc::FatalError, <<~MSG.chomp unless interpreter.is_a?(Tdc::ExtendedAttributes::InterpreterBase)
|
25
23
|
Cannot register an interpreter unless it inherits from Tdc::ExtendedAttributes::InterpreterBase
|
26
24
|
MSG
|
27
25
|
|
28
26
|
@interpreters << interpreter
|
29
27
|
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def default_interpreter
|
32
|
+
@_default_interpreter ||= Tdc::ExtendedAttributes::DefaultInterpreter.new
|
33
|
+
end
|
30
34
|
end
|
31
35
|
end
|
32
36
|
end
|
@@ -3,7 +3,10 @@ module Tdc
|
|
3
3
|
#
|
4
4
|
# Creates ghost methods for use in generators.
|
5
5
|
#
|
6
|
-
# All ghost methods are named 'key'_definition
|
6
|
+
# All ghost methods are named 'key'_definition or 'key'_definition_optional where 'key' is
|
7
|
+
# a key into the instance_definition hash.
|
8
|
+
#
|
9
|
+
# Choose optional if the key may not be present in the instance_definition.
|
7
10
|
#
|
8
11
|
# Example:
|
9
12
|
#
|
@@ -11,6 +14,7 @@ module Tdc
|
|
11
14
|
# ghost methods could be used to refer to the value associated with those keys:
|
12
15
|
#
|
13
16
|
# line_definition
|
17
|
+
# line_definition_optional
|
14
18
|
# replenishment_parameters_definition
|
15
19
|
#
|
16
20
|
module DefinitionSourcable
|
@@ -33,19 +37,25 @@ module Tdc
|
|
33
37
|
private
|
34
38
|
|
35
39
|
def method_missing(method, *args)
|
36
|
-
|
37
|
-
|
38
|
-
|
40
|
+
if ghost_definition?(method)
|
41
|
+
definition_source.fetch(method.to_s.gsub(/_definition$/, ""))
|
42
|
+
elsif ghost_optional_definition?(method)
|
43
|
+
definition_source[method.to_s.gsub(/_definition_optional$/, "")]
|
44
|
+
else
|
45
|
+
super
|
46
|
+
end
|
39
47
|
end
|
40
48
|
|
41
49
|
def respond_to_missing?(method, include_all = false) # rubocop:disable Style/OptionalBooleanParameter
|
42
|
-
|
50
|
+
ghost_definition?(method) || ghost_optional_definition?(method) ? true : super
|
51
|
+
end
|
43
52
|
|
44
|
-
|
53
|
+
def ghost_definition?(method)
|
54
|
+
method.to_s.end_with?("_definition")
|
45
55
|
end
|
46
56
|
|
47
|
-
def
|
48
|
-
method.to_s.
|
57
|
+
def ghost_optional_definition?(method)
|
58
|
+
method.to_s.end_with?("_definition_optional")
|
49
59
|
end
|
50
60
|
end
|
51
61
|
end
|
data/lib/tdc/version.rb
CHANGED
@@ -0,0 +1,52 @@
|
|
1
|
+
module Tdc
|
2
|
+
module YamlReaders
|
3
|
+
#
|
4
|
+
# YAML source.
|
5
|
+
#
|
6
|
+
class YamlReaderBase
|
7
|
+
def initialize(catalog_root_directory, path_elements)
|
8
|
+
@catalog_root_directory = catalog_root_directory
|
9
|
+
@path_elements = path_elements
|
10
|
+
end
|
11
|
+
|
12
|
+
def applies?
|
13
|
+
File.exist?(definitions_file)
|
14
|
+
end
|
15
|
+
|
16
|
+
def data_definitions
|
17
|
+
definitions_source
|
18
|
+
end
|
19
|
+
|
20
|
+
def definitions_source
|
21
|
+
source_string.empty? ? [] : YAML.load(source_string) # rubocop:disable Security/YAMLLoad
|
22
|
+
rescue => e
|
23
|
+
raise Tdc::FatalError, <<~MSG
|
24
|
+
Unable to load YAML from #{definitions_file}
|
25
|
+
Cause: #{e.message}"
|
26
|
+
MSG
|
27
|
+
end
|
28
|
+
|
29
|
+
concerning :HookMethods do
|
30
|
+
def file_extension
|
31
|
+
raise MissingOverrideError, "Implement the 'file_extension' method"
|
32
|
+
end
|
33
|
+
|
34
|
+
def source_string
|
35
|
+
raise MissingOverrideError, "Implement the 'source_string' method"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def definitions_file
|
42
|
+
@_definitions_file ||= begin
|
43
|
+
fully_qualified_path_elements = [@catalog_root_directory].concat(@path_elements.map(&:to_s))
|
44
|
+
|
45
|
+
fully_qualified_path_elements.last.concat(file_extension)
|
46
|
+
|
47
|
+
File.join(*fully_qualified_path_elements)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Tdc
|
2
|
+
module YamlReaders
|
3
|
+
#
|
4
|
+
# Knows how to create the appropriate YAML reader.
|
5
|
+
#
|
6
|
+
class YamlReaderFactory
|
7
|
+
def initialize(catalog_root_directory, path_elements)
|
8
|
+
@catalog_root_directory = catalog_root_directory
|
9
|
+
@path_elements = path_elements
|
10
|
+
end
|
11
|
+
|
12
|
+
def create
|
13
|
+
if yaml_reader_with_expansion.applies?
|
14
|
+
yaml_reader_with_expansion
|
15
|
+
elsif yaml_reader.applies?
|
16
|
+
yaml_reader
|
17
|
+
else
|
18
|
+
null_reader
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def yaml_reader_with_expansion
|
25
|
+
@_yaml_reader_with_expansion ||=
|
26
|
+
Tdc::YamlReaders::YamlReaderWithExpansion.new(@catalog_root_directory, @path_elements)
|
27
|
+
end
|
28
|
+
|
29
|
+
def null_reader
|
30
|
+
@_null_reader ||= Tdc::YamlReaders::NullYamlReader.new
|
31
|
+
end
|
32
|
+
|
33
|
+
def yaml_reader
|
34
|
+
@_yaml_reader ||= Tdc::YamlReaders::YamlReader.new(@catalog_root_directory, @path_elements)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Tdc
|
2
|
+
module YamlReaders
|
3
|
+
#
|
4
|
+
# YAML source is a YAML file that undergoes ERB expansion.
|
5
|
+
#
|
6
|
+
class YamlReaderWithExpansion < Tdc::YamlReaders::YamlReaderBase
|
7
|
+
def file_extension
|
8
|
+
".yml.erb"
|
9
|
+
end
|
10
|
+
|
11
|
+
def source_string
|
12
|
+
ERB.new(File.read(definitions_file)).result
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
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.4.
|
4
|
+
version: 0.4.4
|
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-
|
11
|
+
date: 2020-09-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -147,6 +147,12 @@ files:
|
|
147
147
|
- lib/tdc/missing_override_error.rb
|
148
148
|
- lib/tdc/version.rb
|
149
149
|
- lib/tdc/with_indifferent_access_decorator.rb
|
150
|
+
- lib/tdc/yaml_readers.rb
|
151
|
+
- lib/tdc/yaml_readers/null_yaml_reader.rb
|
152
|
+
- lib/tdc/yaml_readers/yaml_reader.rb
|
153
|
+
- lib/tdc/yaml_readers/yaml_reader_base.rb
|
154
|
+
- lib/tdc/yaml_readers/yaml_reader_factory.rb
|
155
|
+
- lib/tdc/yaml_readers/yaml_reader_with_expansion.rb
|
150
156
|
- tdc.gemspec
|
151
157
|
homepage: https://github.com/nulogy/tdc
|
152
158
|
licenses:
|