tdc 0.4.3.1 → 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 +4 -0
- data/CHANGELOG.md +6 -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/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
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,12 @@ 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
|
+
|
9
15
|
## [0.4.3] - 2020-08-25
|
10
16
|
|
11
17
|
#### 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
|
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:
|