tdc 0.3.9 → 0.4.3.1

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: 40158a1118d92cb453c0197da1eea7850c19ba2bba98306806bf920f167d16b8
4
- data.tar.gz: '09f31030294fadabb38f88c6976d56774670b636ec43bb2ae4d62a96ad234087'
3
+ metadata.gz: f01cdb5f72c9481d031888d6c1729d6ba6976c79184807dfeb4213fa3205ee99
4
+ data.tar.gz: 64ef598c74252a48925ad77c9f779df6c7a45957bb8b2cf641122981c9cfcc30
5
5
  SHA512:
6
- metadata.gz: 40758219403185741dbc04f645f5f7d19a07ff004514cf5c5d9c7a4312085d4918d8d2694204c643bcb97f808c8c958b002b7c2e684748d8d1621e1b9f49f182
7
- data.tar.gz: 41777ff45589fc3de09026e86e0e26220cd863a95861fd866a337f53b23ec0211f4d4ced7d0feac6cabbf563175f6b6234888b441c80d30bd848bad2f42cef16
6
+ metadata.gz: d093ea28c783c4a5b62c951c815cfb915c7ae7cf13ec2e97cb6ddaceedb09b968b6bb6bf9d80723d8146edac1c7bb6c562d59dec957d074cd67f985a0ce4c79f
7
+ data.tar.gz: c99360136e1857226fef356850499c8aa4bfbe5762c808ab115e4ca40bf4a8f9b097d06dc7c277e0b50e77e9655a2056dc544ca733552238c6de3b203b391c37
@@ -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,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.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
+
9
31
  ## [0.3.9] - 2020-08-12
10
32
 
11
33
  #### Breaking Changes
@@ -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
@@ -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 where 'key' is a key into the instance_definition hash.
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
- key = transform_method_to_definition_source_key(method)
37
-
38
- definition_source&.key?(key) ? definition_source.fetch(key) : super
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
- key = transform_method_to_definition_source_key(method)
50
+ ghost_definition?(method) || ghost_optional_definition?(method) ? true : super
51
+ end
43
52
 
44
- definition_source&.key?(key) ? true : super
53
+ def ghost_definition?(method)
54
+ method.to_s.end_with?("_definition")
45
55
  end
46
56
 
47
- def transform_method_to_definition_source_key(method)
48
- method.to_s.gsub(/_definition$/, "")
57
+ def ghost_optional_definition?(method)
58
+ method.to_s.end_with?("_definition_optional")
49
59
  end
50
60
  end
51
61
  end
@@ -1,3 +1,3 @@
1
1
  module Tdc
2
- VERSION = "0.3.9"
2
+ VERSION = "0.4.3.1"
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.9
4
+ version: 0.4.3.1
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-12 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