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 +4 -4
- data/.rubocop.yml +4 -0
- data/CHANGELOG.md +22 -0
- data/lib/tdc/data_definition_file_reader.rb +1 -7
- data/lib/tdc/extended_attributes/default_interpreter.rb +27 -11
- data/lib/tdc/extended_attributes/interpreter_registry.rb +8 -4
- data/lib/tdc/generators/catalog_entries.rb +5 -1
- data/lib/tdc/generators/definition_sourcable.rb +18 -8
- data/lib/tdc/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f01cdb5f72c9481d031888d6c1729d6ba6976c79184807dfeb4213fa3205ee99
|
4
|
+
data.tar.gz: 64ef598c74252a48925ad77c9f779df6c7a45957bb8b2cf641122981c9cfcc30
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d093ea28c783c4a5b62c951c815cfb915c7ae7cf13ec2e97cb6ddaceedb09b968b6bb6bf9d80723d8146edac1c7bb6c562d59dec957d074cd67f985a0ce4c79f
|
7
|
+
data.tar.gz: c99360136e1857226fef356850499c8aa4bfbe5762c808ab115e4ca40bf4a8f9b097d06dc7c277e0b50e77e9655a2056dc544ca733552238c6de3b203b391c37
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -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
|
-
|
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 |
|
8
|
-
# Remove the
|
9
|
-
instance_definition.delete(
|
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(
|
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
|
-
|
26
|
-
|
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
|
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
|
@@ -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
|
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
|
-
|
37
|
-
|
38
|
-
|
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
|
-
|
50
|
+
ghost_definition?(method) || ghost_optional_definition?(method) ? true : super
|
51
|
+
end
|
43
52
|
|
44
|
-
|
53
|
+
def ghost_definition?(method)
|
54
|
+
method.to_s.end_with?("_definition")
|
45
55
|
end
|
46
56
|
|
47
|
-
def
|
48
|
-
method.to_s.
|
57
|
+
def ghost_optional_definition?(method)
|
58
|
+
method.to_s.end_with?("_definition_optional")
|
49
59
|
end
|
50
60
|
end
|
51
61
|
end
|
data/lib/tdc/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2020-08-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|