tdc 0.3.8 → 0.4.3

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: 2887adedbcb323e7d03e75b65538c2afc1edbe5f4ea84c0555e50dda77bc1305
4
- data.tar.gz: a8be475b6e7edcd72ab2047cab59a198e984b921d4893ca5bac25ef0476540ea
3
+ metadata.gz: 8f5936018f214ecc5b2c99c96aaeaa02b01b1376ba09266202b82662dc3f0cce
4
+ data.tar.gz: f2572c85877de786307abe6ad4b3e7720cc9d3acd02398523f4d779e0dbbdf57
5
5
  SHA512:
6
- metadata.gz: f1aaaf060b8e5b85ab96487279471521b9a04738a63cf360473905a6834d08bfc3bd3ddef01c5b2e571736b87177b74a21ee5cba24860e56bcdb206e208e3962
7
- data.tar.gz: dc9cd3002213b1b5c2f6d95f09b986249c30fe239a28e788f06462d00f496b02a3cbc707d5236bd987d44ea435e9b516adbb777f480cce24a0ca22a06b59fe52
6
+ metadata.gz: 85846a6e8b1d30f3ed7eaeb893f4cc9cc3982723789c47bae6673fa91b65e54f7f0c4de8d05cd0f2989a2165ebb952b4311cabd22e0f38aabcea337bb39e158e
7
+ data.tar.gz: b05b075225180aa3711691d3ac6000cc9f9a2508fb11b82a6e01dd864092e42624e0b8bb157b4a03c139629a87711b4a083ad83f3e42eb1da78edd26a26b57aa
@@ -21,6 +21,10 @@ Metrics/BlockLength:
21
21
  Naming/MemoizedInstanceVariableName:
22
22
  EnforcedStyleForLeadingUnderscores: required
23
23
 
24
+ Naming/VariableNumber:
25
+ Enabled: true
26
+ EnforcedStyle: snake_case
27
+
24
28
  RSpec/AnyInstance:
25
29
  Enabled: false
26
30
 
@@ -6,6 +6,34 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.4.3] - 2020-08-25
10
+
11
+ #### New Features
12
+
13
+ - Support optional definitions
14
+
15
+ ## [0.4.2] - 2020-08-22
16
+
17
+ #### Breaking Changes
18
+
19
+ - Extended attributes use `_xa` suffix
20
+
21
+ ## [0.4.1] - 2020-08-22
22
+
23
+ - Add the `first` method to `CatalogEntries`
24
+
25
+ ## [0.4.0] - 2020-08-14
26
+
27
+ #### New Features
28
+
29
+ - Drop requirement that an empty test data definition file must be provided
30
+
31
+ ## [0.3.9] - 2020-08-12
32
+
33
+ #### Breaking Changes
34
+
35
+ - Collapse `ConfigurableGenerator` into `StandardGenerator`
36
+
9
37
  ## [0.3.8] - 2020-08-11
10
38
 
11
39
  #### New Features
Binary file
data/lib/tdc.rb CHANGED
@@ -39,7 +39,6 @@ require "tdc/generators/definition_sourcable"
39
39
 
40
40
  # Generator Hierarchy
41
41
  require "tdc/generators/generator_base"
42
- require "tdc/generators/configurable_generator"
43
42
  require "tdc/generators/standard_generator"
44
43
 
45
44
  #
@@ -29,7 +29,7 @@ module Tdc
29
29
  if File.exist?(definitions_file)
30
30
  load_yaml(definitions_file) || EMPTY_DEFINITIONS
31
31
  else
32
- missing_data_definition(definitions_file)
32
+ EMPTY_DEFINITIONS
33
33
  end
34
34
  end
35
35
 
@@ -45,11 +45,5 @@ module Tdc
45
45
  def expand_erb(definitions_file)
46
46
  ERB.new(File.read(definitions_file)).result
47
47
  end
48
-
49
- def missing_data_definition(definitions_file)
50
- return EMPTY_DEFINITIONS if ENV.key?("TDC_IGNORE_MISSING_TEST_DATA_DEFINITION_ERROR")
51
-
52
- raise Tdc::FatalError, "Missing test definitions file: '#{definitions_file}'"
53
- end
54
48
  end
55
49
  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 |k, v|
8
- # Remove the original extended attribute.
9
- instance_definition.delete(k)
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(k)] = extended_attribute_context.instance_eval(v)
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
- def keep_extended_attributes(instance_definition)
26
- instance_definition.select { |k, _v| /_(at|date|on)x$/ =~ k }
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 << Tdc::ExtendedAttributes::DefaultInterpreter.new if @interpreters.empty?
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
@@ -13,10 +13,14 @@ module Tdc
13
13
  to_h.empty?
14
14
  end
15
15
 
16
+ def first
17
+ to_h.first&.second
18
+ end
19
+
16
20
  def single_entry
17
21
  raise Tdc::FatalError, "There is more than one entry" if to_h.many?
18
22
 
19
- to_h.first.second
23
+ first
20
24
  end
21
25
  end
22
26
  end
@@ -33,20 +33,30 @@ module Tdc
33
33
  private
34
34
 
35
35
  def method_missing(method, *args)
36
- key = transform_method_to_definition_source_key(method)
37
-
38
- definition_source&.key?(key) ? definition_source.fetch(key) : super
36
+ if definition?(method)
37
+ definition_source.fetch(method.to_s.gsub(/_definition$/, ""))
38
+ elsif optional_definition?(method)
39
+ definition_source[method.to_s.gsub(/_definition_optional$/, "")]
40
+ else
41
+ super
42
+ end
39
43
  end
40
44
 
41
45
  def respond_to_missing?(method, include_all = false) # rubocop:disable Style/OptionalBooleanParameter
42
- key = transform_method_to_definition_source_key(method)
43
-
44
- definition_source&.key?(key) ? true : super
46
+ definition?(method) || definition_optional?(method) ? true : super
45
47
  end
46
48
 
47
49
  def transform_method_to_definition_source_key(method)
48
50
  method.to_s.gsub(/_definition$/, "")
49
51
  end
52
+
53
+ def definition?(method)
54
+ method.to_s.end_with?("_definition")
55
+ end
56
+
57
+ def optional_definition?(method)
58
+ method.to_s.end_with?("_definition_optional")
59
+ end
50
60
  end
51
61
  end
52
62
  end
@@ -1,11 +1,15 @@
1
1
  module Tdc
2
2
  module Generators
3
3
  #
4
- # Abstract class for defining generators that define a collection of model instances.
4
+ # Knows how to provide a configurable instance definition.
5
5
  #
6
- # See also SingularGenerator.
7
- #
8
- class StandardGenerator < Tdc::Generators::ConfigurableGenerator
6
+ class StandardGenerator < Tdc::Generators::GeneratorBase
7
+ include Tdc::Generators::DefinitionSourcable
8
+
9
+ attr_reader :instance_definition
10
+
11
+ source_definition_from :instance_definition
12
+
9
13
  def generate
10
14
  CatalogEntries.new.tap do |catalog_entries|
11
15
  instance_definitions.each do |instance_definition|
@@ -21,6 +25,43 @@ module Tdc
21
25
  end
22
26
  end
23
27
  end
28
+
29
+ def run_resolvers_and_generate_instance
30
+ run_extended_attribute_interpreters(instance_definition)
31
+ run_definition_resolvers(instance_definition)
32
+
33
+ generate_instance
34
+ end
35
+
36
+ #
37
+ # Hook method: subclasses are expected to define how to generate a model instance.
38
+ #
39
+ def generate_instance
40
+ raise Tdc::MissingOverrideError, "Implement the 'generate_instance' method"
41
+ end
42
+
43
+ #
44
+ # Hook method: subclasses may include the DefinitionResolvable concern to override.
45
+ #
46
+ def run_definition_resolvers(_instance_definition)
47
+ # Do nothing
48
+ end
49
+
50
+ private
51
+
52
+ def configure_instance_definition(instance_definition)
53
+ @instance_definition = instance_definition
54
+
55
+ configure_definition_source(instance_definition)
56
+ end
57
+
58
+ def run_extended_attribute_interpreters(instance_definition)
59
+ interpreters.each { |interpreter| interpreter.interpret(instance_definition) }
60
+ end
61
+
62
+ def interpreters
63
+ Tdc::ExtendedAttributes::InterpreterRegistry.instance.interpreters
64
+ end
24
65
  end
25
66
  end
26
67
  end
@@ -1,3 +1,3 @@
1
1
  module Tdc
2
- VERSION = "0.3.8"
2
+ VERSION = "0.4.3"
3
3
  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.3.8
4
+ version: 0.4.3
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-11 00:00:00.000000000 Z
11
+ date: 2020-08-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -138,7 +138,6 @@ files:
138
138
  - lib/tdc/fatal_error.rb
139
139
  - lib/tdc/generators.rb
140
140
  - lib/tdc/generators/catalog_entries.rb
141
- - lib/tdc/generators/configurable_generator.rb
142
141
  - lib/tdc/generators/definition_resolvable.rb
143
142
  - lib/tdc/generators/definition_sourcable.rb
144
143
  - lib/tdc/generators/generation_context.rb
@@ -1,51 +0,0 @@
1
- module Tdc
2
- module Generators
3
- #
4
- # Knows how to provide a configurable instance definition.
5
- #
6
- class ConfigurableGenerator < Tdc::Generators::GeneratorBase
7
- include Tdc::Generators::DefinitionSourcable
8
-
9
- attr_reader :instance_definition
10
-
11
- source_definition_from :instance_definition
12
-
13
- def run_resolvers_and_generate_instance
14
- run_extended_attribute_interpreters(instance_definition)
15
- run_definition_resolvers(instance_definition)
16
-
17
- generate_instance
18
- end
19
-
20
- #
21
- # Hook method: subclasses are expected to define how to generate a model instance.
22
- #
23
- def generate_instance
24
- raise Tdc::MissingOverrideError, "Implement the 'generate_instance' method"
25
- end
26
-
27
- #
28
- # Hook method: subclasses may include the DefinitionResolvable concern to override.
29
- #
30
- def run_definition_resolvers(_instance_definition)
31
- # Do nothing
32
- end
33
-
34
- private
35
-
36
- def configure_instance_definition(instance_definition)
37
- @instance_definition = instance_definition
38
-
39
- configure_definition_source(instance_definition)
40
- end
41
-
42
- def run_extended_attribute_interpreters(instance_definition)
43
- interpreters.each { |interpreter| interpreter.interpret(instance_definition) }
44
- end
45
-
46
- def interpreters
47
- Tdc::ExtendedAttributes::InterpreterRegistry.instance.interpreters
48
- end
49
- end
50
- end
51
- end