tdc 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 523892b0a0a870a9b4c5a6abe2b7e0cac37b8dfb51249e50da32fcac29c3e6f6
4
- data.tar.gz: 616521e4890e99edf594c8b6778b2f4ee7680e713077ba4cf08811b91d4adf26
3
+ metadata.gz: 9c04de93f4bf48d68994ce4b8adab06f21ebd2f44e3d47ce6f221400cdc8495d
4
+ data.tar.gz: 93a7c7a9d9dc4ea4480cc464cf6dc7c6526b6e941a68d74de956572e3fe71864
5
5
  SHA512:
6
- metadata.gz: e6c1bf80620c67f96f89234a7b578c3a97d42b64a732c1048d489902206f9caa859c998c684f10ac38b87ac67a1cfe11340438708aa391c524381470737265a3
7
- data.tar.gz: d1df65063610d080e53cc57f61b64bca1f48111fb99240702547f609c5f8b446b698de6d816b0f4d4e64d7c9813daad466567ee47df759e9fda497f97a8aa6a4
6
+ metadata.gz: 4986b573ecf8e32558cbfafddba2218a21896f7b01c6197b42bdab1b117cdee729dd3f0cc58fb8907e577223dad3fcd42890a8fedc937e1a9f4280a3be2be224
7
+ data.tar.gz: 25aad449a81724ff044343015835148683c540ba3080d298841152bca2b5ac79d29557f1b2de17d7e986d1556629c20a542e4360a7ece7c3c6998c3fc5971402
data/CHANGELOG.md CHANGED
@@ -6,6 +6,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.2.0] - 2020-05-19
10
+
11
+ #### Breaking Changes
12
+
13
+ - Renamed TestDataDefinitionReader to DataDefinitionFileReader
14
+ - All errors inherit from Tdc::FatalError
15
+
9
16
  ## [0.1.2] - 2020-05-18
10
17
 
11
18
  - Complete the extraction from PackManager
data/README.md CHANGED
@@ -1,2 +1,13 @@
1
- # TDC: Test Data Catalog
1
+ # TDC: Test Data Catalog Generation
2
2
 
3
+ ![TDC Framelet](/images/Tdc.png)
4
+
5
+ **Extension Points**
6
+
7
+ Define your own test data generators by inheriting from ```StandardGenerator``` or ```Singular Generator```.
8
+
9
+ 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
+
11
+ **Data Definition DSL**
12
+
13
+ ```DefinitionResolvable``` and ```DefinitionSourcable``` provide a DSL that you may use in your generators to work more easily with a ```DataDefinition```.
data/images/Tdc.png ADDED
Binary file
data/lib/tdc.rb CHANGED
@@ -3,8 +3,10 @@ require "ostruct"
3
3
  require "active_support/concern"
4
4
  require "active_support/core_ext/hash/indifferent_access"
5
5
 
6
+ require "tdc/data_definition"
7
+ require "tdc/data_definition_file_reader"
8
+ require "tdc/fatal_error"
6
9
  require "tdc/in_memory_data_definition"
7
- require "tdc/test_data_definition_reader"
8
10
  require "tdc/version"
9
11
  require "tdc/with_indifferent_access_decorator"
10
12
 
@@ -17,14 +19,6 @@ require "tdc/generators/instance_definition_configurable"
17
19
  require "tdc/generators/singular_generator"
18
20
  require "tdc/generators/standard_generator"
19
21
 
20
- require "tdc/decorator_error"
21
- require "tdc/missing_hook_override_error"
22
- require "tdc/missing_path_elements_error"
23
- require "tdc/missing_test_data_definition_error"
24
- require "tdc/non_singular_instance_error"
25
- require "tdc/unresolvable_tag_error"
26
- require "tdc/yaml_load_error"
27
-
28
22
  #
29
23
  # A framework for building a Test Data Catalog
30
24
  #
@@ -0,0 +1,14 @@
1
+ module Tdc
2
+ #
3
+ # Knows how to read data definitions from the specified path elements.
4
+ #
5
+ class DataDefinition
6
+ def read(*_path_elements)
7
+ raise MissingOverrideError
8
+ end
9
+
10
+ def with_indifferent_access
11
+ self.extend(Tdc::WithIndifferentAccessDecorator) # rubocop:disable Style/RedundantSelf
12
+ end
13
+ end
14
+ end
@@ -1,8 +1,8 @@
1
1
  module Tdc
2
2
  #
3
- # Knows how to read test data definitions from YAML files.
3
+ # Knows how to read data definitions from YAML files.
4
4
  #
5
- class TestDataDefinitionReader
5
+ class DataDefinitionFileReader < Tdc::DataDefinition
6
6
  EMPTY_DEFINITIONS = []
7
7
 
8
8
  def initialize(catalog_root_directory)
@@ -13,10 +13,6 @@ module Tdc
13
13
  data_definition_from(definitions_file(path_elements))
14
14
  end
15
15
 
16
- def with_indifferent_access
17
- self.extend(Tdc::WithIndifferentAccessDecorator) # rubocop:disable Style/RedundantSelf
18
- end
19
-
20
16
  private
21
17
 
22
18
  def definitions_file(path_elements)
@@ -38,7 +34,7 @@ module Tdc
38
34
  def load_yaml(definitions_file)
39
35
  YAML.load(expand_erb(definitions_file)) # rubocop:disable Security/YAMLLoad
40
36
  rescue => e
41
- raise Tdc::YamlLoadError, <<~MSG
37
+ raise Tdc::FatalError, <<~MSG
42
38
  Unable to load YAML from #{definitions_file}
43
39
  Cause: #{e.message}"
44
40
  MSG
@@ -51,7 +47,7 @@ module Tdc
51
47
  def missing_data_definition(definitions_file)
52
48
  return EMPTY_DEFINITIONS if ENV.key?("TDC_IGNORE_MISSING_TEST_DATA_DEFINITION_ERROR")
53
49
 
54
- raise MissingTestDataDefinitionError, definitions_file
50
+ raise Tdc::FatalError, "Missing test definitions file: '#{definitions_file}'"
55
51
  end
56
52
  end
57
53
  end
@@ -0,0 +1,7 @@
1
+ module Tdc
2
+ class FatalError < RuntimeError
3
+ def initialize(msg = nil)
4
+ super
5
+ end
6
+ end
7
+ end
@@ -51,7 +51,7 @@ module Tdc
51
51
  unless sourced_object
52
52
  message = "Could not find a tag reference for '#{key}' in the catalog entries provided."
53
53
 
54
- raise Tdc::UnresolvableTagError, message
54
+ raise Tdc::FatalError, message
55
55
  end
56
56
 
57
57
  # Replace the tag value with the sourced object.
@@ -12,11 +12,11 @@ module Tdc
12
12
  end
13
13
 
14
14
  def generate
15
- raise Tdc::MissingHookOverrideError
15
+ raise Tdc::MissingOverrideError
16
16
  end
17
17
 
18
18
  def instance_definitions
19
- raise Tdc::MissingHookOverrideError
19
+ raise Tdc::MissingOverrideError
20
20
  end
21
21
  end
22
22
  end
@@ -34,7 +34,7 @@ module Tdc
34
34
  # Hook method: subclasses are expected to define how to generate a model instance.
35
35
  #
36
36
  def generate_instance
37
- raise Tdc::MissingHookOverrideError
37
+ raise Tdc::MissingOverrideError
38
38
  end
39
39
 
40
40
  #
@@ -32,7 +32,7 @@ module Tdc
32
32
  all_instance_definitions = instance_definitions
33
33
 
34
34
  if all_instance_definitions.many?
35
- raise Tdc::NonSingularInstanceError, "For the moment we only generate a single model instance"
35
+ raise Tdc::FatalError, "For the moment we only generate a single model instance"
36
36
  end
37
37
 
38
38
  # Delete the tag so that the models do not need to filter it out.
@@ -1,24 +1,20 @@
1
1
  module Tdc
2
2
  #
3
- # Knows how to read test data definitions from an in-memory representation.
3
+ # Knows how to read data definitions from an in-memory representation.
4
4
  #
5
- class InMemoryDataDefinition
5
+ class InMemoryDataDefinition < Tdc::DataDefinition
6
6
  def initialize(path_elements_data = {})
7
7
  @store = path_elements_data
8
8
  end
9
9
 
10
- def store(path_elements, data)
11
- @store[path_elements] = data
12
- end
13
-
14
10
  def read(*path_elements)
15
11
  @store.fetch(path_elements) do
16
- raise MissingPathElementsError, "The path did not have any data associated with it: #{path_elements.inspect}"
12
+ raise Tdc::FatalError, "The path did not have any data associated with it: #{path_elements.inspect}"
17
13
  end
18
14
  end
19
15
 
20
- def with_indifferent_access
21
- self.extend(Tdc::WithIndifferentAccessDecorator) # rubocop:disable Style/RedundantSelf
16
+ def store(path_elements, data)
17
+ @store[path_elements] = data
22
18
  end
23
19
  end
24
20
  end
@@ -1,5 +1,5 @@
1
1
  module Tdc
2
- class MissingHookOverrideError < RuntimeError
2
+ class MissingOverrideError < Tdc::FatalError
3
3
  def initialize
4
4
  super("Must be implemented")
5
5
  end
data/lib/tdc/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Tdc
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -7,7 +7,7 @@ module Tdc
7
7
  def read(*path_elements)
8
8
  definitions = super
9
9
 
10
- raise DecoratorError, "Use 'with_indifferent_access' only for an Array" unless definitions.is_a?(Array)
10
+ raise Tdc::FatalError, "Use 'with_indifferent_access' only for an Array" unless definitions.is_a?(Array)
11
11
 
12
12
  definitions.map do |definition|
13
13
  definition.is_a?(Hash) ? ActiveSupport::HashWithIndifferentAccess.new(definition) : definition
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.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alistair McKinnell
@@ -123,8 +123,11 @@ files:
123
123
  - Rakefile
124
124
  - bin/console
125
125
  - bin/setup
126
+ - images/Tdc.png
126
127
  - lib/tdc.rb
127
- - lib/tdc/decorator_error.rb
128
+ - lib/tdc/data_definition.rb
129
+ - lib/tdc/data_definition_file_reader.rb
130
+ - lib/tdc/fatal_error.rb
128
131
  - lib/tdc/generators.rb
129
132
  - lib/tdc/generators/catalog_entries.rb
130
133
  - lib/tdc/generators/definition_resolvable.rb
@@ -134,15 +137,9 @@ files:
134
137
  - lib/tdc/generators/singular_generator.rb
135
138
  - lib/tdc/generators/standard_generator.rb
136
139
  - lib/tdc/in_memory_data_definition.rb
137
- - lib/tdc/missing_hook_override_error.rb
138
- - lib/tdc/missing_path_elements_error.rb
139
- - lib/tdc/missing_test_data_definition_error.rb
140
- - lib/tdc/non_singular_instance_error.rb
141
- - lib/tdc/test_data_definition_reader.rb
142
- - lib/tdc/unresolvable_tag_error.rb
140
+ - lib/tdc/missing_override_error.rb
143
141
  - lib/tdc/version.rb
144
142
  - lib/tdc/with_indifferent_access_decorator.rb
145
- - lib/tdc/yaml_load_error.rb
146
143
  - tdc.gemspec
147
144
  homepage: https://github.com/nulogy/tdc
148
145
  licenses: []
@@ -1,3 +0,0 @@
1
- module Tdc
2
- DecoratorError = Class.new(RuntimeError)
3
- end
@@ -1,3 +0,0 @@
1
- module Tdc
2
- MissingPathElementsError = Class.new(RuntimeError)
3
- end
@@ -1,3 +0,0 @@
1
- module Tdc
2
- MissingTestDataDefinitionError = Class.new(RuntimeError)
3
- end
@@ -1,3 +0,0 @@
1
- module Tdc
2
- NonSingularInstanceError = Class.new(RuntimeError)
3
- end
@@ -1,3 +0,0 @@
1
- module Tdc
2
- UnresolvableTagError = Class.new(RuntimeError)
3
- end
@@ -1,3 +0,0 @@
1
- module Tdc
2
- YamlLoadError = Class.new(RuntimeError)
3
- end