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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f01cdb5f72c9481d031888d6c1729d6ba6976c79184807dfeb4213fa3205ee99
4
- data.tar.gz: 64ef598c74252a48925ad77c9f779df6c7a45957bb8b2cf641122981c9cfcc30
3
+ metadata.gz: 9afbee316bed8c63956e2a3f1626e376101940ecbb83e45fc6f7dd699d626df4
4
+ data.tar.gz: c4f164c51b6421490d157cbf4761ad4d9e634af72a6a52a6bce0443cfd4b32a9
5
5
  SHA512:
6
- metadata.gz: d093ea28c783c4a5b62c951c815cfb915c7ae7cf13ec2e97cb6ddaceedb09b968b6bb6bf9d80723d8146edac1c7bb6c562d59dec957d074cd67f985a0ce4c79f
7
- data.tar.gz: c99360136e1857226fef356850499c8aa4bfbe5762c808ab115e4ca40bf4a8f9b097d06dc7c277e0b50e77e9655a2056dc544ca733552238c6de3b203b391c37
6
+ metadata.gz: fd3f18ae6079f57dce2faa700c27ec64c86f266eb54820a2952beeeefcf3d4e8bcb0a785e69b02b222bcfa29f56ad5484c888dcea3d8d74e58610435ac4273e0
7
+ data.tar.gz: 219c4136fc7dc4717e9c83849d7318cbe05751b661dd9d95bbbaa2cc5a621188a44b13b7e2624c9c80c4126e34ced7274673dabe0af6e62488977cefa26e29ac
@@ -15,6 +15,10 @@ 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
 
@@ -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
- data_definition_from(definitions_file(path_elements))
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
- def expand_erb(definitions_file)
46
- ERB.new(File.read(definitions_file)).result
15
+ reader.data_definitions
47
16
  end
48
17
  end
49
18
  end
@@ -8,8 +8,6 @@ module Tdc
8
8
  attr_reader :key, :source
9
9
 
10
10
  def initialize(key:, source:)
11
- super()
12
-
13
11
  @key = key
14
12
  @source = source
15
13
  end
@@ -4,8 +4,6 @@ module Tdc
4
4
  #
5
5
  class InMemoryDataDefinition < Tdc::DataDefinition
6
6
  def initialize(path_elements_data = {})
7
- super()
8
-
9
7
  @store = path_elements_data
10
8
  end
11
9
 
@@ -1,3 +1,3 @@
1
1
  module Tdc
2
- VERSION = "0.4.3.1"
2
+ VERSION = "0.4.4"
3
3
  end
@@ -0,0 +1,7 @@
1
+ module Tdc
2
+ #
3
+ # Namespace to host YAML readers.
4
+ #
5
+ module YamlReaders
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ module Tdc
2
+ module YamlReaders
3
+ #
4
+ # When we can't find a YAML source.
5
+ #
6
+ class NullYamlReader
7
+ def data_definitions
8
+ []
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,16 @@
1
+ module Tdc
2
+ module YamlReaders
3
+ #
4
+ # YAML source is a YAML file.
5
+ #
6
+ class YamlReader < Tdc::YamlReaders::YamlReaderBase
7
+ def file_extension
8
+ ".yml"
9
+ end
10
+
11
+ def source_string
12
+ File.read(definitions_file)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -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.3.1
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-08-25 00:00:00.000000000 Z
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: