tdc 0.3.1 → 0.3.6

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: 46a2a39e062ccd48c5634a1c0f2fb07e5705268ceb930bb0dc4b41127683406b
4
- data.tar.gz: 9ea9e2f9ddf8bb1696151426ab584a734544ed51c9dac67d2e153293707b522b
3
+ metadata.gz: afd309b8d6f641f50856a6ab71c6557dceba91c43e97c6d23a54f526cc954570
4
+ data.tar.gz: c730e903a12d47f4a8dc452a212ae9f38f75a4d2b61a74dd72237e69f0005d47
5
5
  SHA512:
6
- metadata.gz: 15cab57dccd6be42ab9f1de3782db7df1f29c33f20196aa40ba4b7cfaf36fe4a30a84ee7d8b0b4f38dbccf6afd24b6580b21fe1c9a6afa2d78eae8852eac889c
7
- data.tar.gz: e7182a480f845f3e196354c2d170df24f9a762f57db3993c9ca8e266425d01637960f588ae938484a9731e99d7b5bc9f71b1921773b6d3450f02d681515d89fd
6
+ metadata.gz: f699b62e54e48f3b42bb06215a8e783ca15797265292e988f70f4cbc82191aa55174ccfbcdf1bb50b58ccb1323716272d7d958283b49eac45dbb1c948208f616
7
+ data.tar.gz: 7496da7a34c508a1b132a5232f1c061eded18b8b5057192728be98b3faae095b3c3e1dd377b2563fde95f897861bcedb932bf867c8f20c4e3f09621af18cf52d
@@ -10,6 +10,9 @@ AllCops:
10
10
  Layout/EmptyLinesAroundAttributeAccessor:
11
11
  Enabled: true
12
12
 
13
+ Metrics/LineLength:
14
+ Max: 120
15
+
13
16
  # Rubocop and I cannot agree.
14
17
  Layout/MultilineMethodCallBraceLayout:
15
18
  Enabled: false
@@ -26,7 +29,6 @@ Lint/DuplicateElsifCondition:
26
29
  Lint/MixedRegexpCaptureTypes:
27
30
  Enabled: true
28
31
 
29
-
30
32
  Lint/RaiseException:
31
33
  Enabled: true
32
34
 
@@ -45,9 +47,6 @@ RSpec/AnyInstance:
45
47
  RSpec/ExampleLength:
46
48
  Max: 15
47
49
 
48
- Metrics/LineLength:
49
- Max: 120
50
-
51
50
  RSpec/DescribeClass:
52
51
  Enabled: false
53
52
 
@@ -121,6 +120,10 @@ Style/HashSyntax:
121
120
  Exclude:
122
121
  - 'Rakefile'
123
122
 
123
+ # We are not going to optimize by freezing strings.
124
+ Style/MutableConstant:
125
+ Enabled: false
126
+
124
127
  Style/RedundantAssignment:
125
128
  Enabled: true
126
129
 
@@ -151,6 +154,6 @@ Style/StringLiterals:
151
154
  Style/SymbolArray:
152
155
  Enabled: false
153
156
 
154
- # We are not going to optimize by freezing strings.
155
- Style/MutableConstant:
157
+ # I prefer not to use %w or %W for an array of words.
158
+ Style/WordArray:
156
159
  Enabled: false
@@ -6,6 +6,36 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.3.6] - 2020-08-06
10
+
11
+ #### Breaking Changes
12
+
13
+ - Drop the `SingularGenerator` abstraction
14
+
15
+ ## [0.3.5] - 2020-08-06
16
+
17
+ - Add the `single_entry` method to `CatalogEntries`
18
+
19
+ #### Breaking Changes
20
+
21
+ - Drop the `with_definition` method from `SingularGenerator`
22
+
23
+ ## [0.3.4] - 2020-08-05
24
+
25
+ #### Breaking Changes
26
+
27
+ - Introduce the `GenerationContext` abstraction
28
+ - All generators are initialized with an instance of `Tdc::Generators::GenerationContext`
29
+
30
+ ## [0.3.3] - 2020-08-04
31
+
32
+ - Add the `empty?` method to `CatalogEntries`
33
+ - Evaluate `_atx` attribute values against a `Time.zone` instance
34
+
35
+ ## [0.3.2] - 2020-07-27
36
+
37
+ - Return `self` from `DefinitionResolver#configure_current_catalog` to make it chainable
38
+
9
39
  ## [0.3.1] - 2020-07-25
10
40
 
11
41
  - Support DefinitionResolver instance registration
@@ -46,5 +76,3 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
46
76
  #### New Features
47
77
 
48
78
  - Avoid all PackManager dependencies
49
-
50
-
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  **Extension Points**
6
6
 
7
- Define your own test data generators by inheriting from ```StandardGenerator``` or ```SingularGenerator```. Best practice is to define an ```ApplicationStandardGenerator``` and an ```ApplicationSingularGenerator``` and have all other generators inherit from them.
7
+ Define your own test data generators by inheriting from ```StandardGenerator```. Best practice is to define an ```ApplicationStandardGenerator``` and have all other generators inherit from it.
8
8
 
9
9
  Define your own definition resolvers by inheriting from ```DefinitionResolver```. Best practice is to define an ```ApplicationDefinitionResolver``` and all other definition resolvers inherit from it.
10
10
 
Binary file
data/lib/tdc.rb CHANGED
@@ -19,6 +19,7 @@ require "tdc/with_indifferent_access_decorator"
19
19
 
20
20
  # Generators
21
21
  require "tdc/generators"
22
+ require "tdc/generators/generation_context"
22
23
 
23
24
  # Current Catalog
24
25
  require "tdc/generators/catalog_entries"
@@ -30,7 +31,6 @@ require "tdc/generators/definition_sourcable"
30
31
  # Generator Hierarchy
31
32
  require "tdc/generators/generator_base"
32
33
  require "tdc/generators/configurable_generator"
33
- require "tdc/generators/singular_generator"
34
34
  require "tdc/generators/standard_generator"
35
35
 
36
36
  # Definition Resolvers
@@ -8,6 +8,8 @@ module Tdc
8
8
 
9
9
  def configure_current_catalog(current_catalog)
10
10
  @current_catalog = current_catalog
11
+
12
+ self
11
13
  end
12
14
 
13
15
  def resolve(_instance_definition)
@@ -8,6 +8,16 @@ module Tdc
8
8
  def add_catalog_entry(tag, entry)
9
9
  send("#{tag}=", entry)
10
10
  end
11
+
12
+ def empty?
13
+ to_h.empty?
14
+ end
15
+
16
+ def single_entry
17
+ raise Tdc::FatalError, "There is more than one entry" if to_h.many?
18
+
19
+ to_h.first.second
20
+ end
11
21
  end
12
22
  end
13
23
  end
@@ -44,12 +44,15 @@ module Tdc
44
44
  def run_atx_resolvers(instance_definition)
45
45
  atx_definitions = instance_definition.select { |k, _v| /_atx$/ =~ k }
46
46
 
47
+ # ARM (2020-08-04): Move all the way out so that all generators use the same atx_context.
48
+ atx_context = Time.zone
49
+
47
50
  atx_definitions.each do |k, v|
48
51
  # Remove the original _atx attribute.
49
52
  instance_definition.delete(k)
50
53
 
51
54
  # Add a standard _at attribute.
52
- instance_definition[k.delete_suffix("x")] = eval(v) # rubocop:disable Security/Eval
55
+ instance_definition[k.delete_suffix("x")] = atx_context.instance_eval(v)
53
56
  end
54
57
  end
55
58
  end
@@ -0,0 +1,15 @@
1
+ module Tdc
2
+ module Generators
3
+ #
4
+ # Knows all the parameters that define the context for generation.
5
+ #
6
+ class GenerationContext
7
+ attr_reader :current_catalog, :data_definition
8
+
9
+ def initialize(current_catalog:, data_definition:)
10
+ @current_catalog = current_catalog
11
+ @data_definition = data_definition
12
+ end
13
+ end
14
+ end
15
+ end
@@ -4,11 +4,13 @@ module Tdc
4
4
  # Abstract base class for all Test Data Catalog generators.
5
5
  #
6
6
  class GeneratorBase
7
- attr_reader :data_definition, :current_catalog
7
+ attr_reader :generation_context
8
8
 
9
- def initialize(data_definition, current_catalog)
10
- @data_definition = data_definition
11
- @current_catalog = current_catalog
9
+ # ARM (2020-08-05): For backwards compatibility. Consider removing.
10
+ delegate :current_catalog, :data_definition, to: :generation_context
11
+
12
+ def initialize(generation_context)
13
+ @generation_context = generation_context
12
14
  end
13
15
 
14
16
  def generate
@@ -1,3 +1,3 @@
1
1
  module Tdc
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.6"
3
3
  end
@@ -8,6 +8,7 @@ Gem::Specification.new do |spec|
8
8
 
9
9
  spec.summary = "A simple framework for creating a Test Data Catalog"
10
10
  spec.homepage = "https://github.com/nulogy/tdc"
11
+ spec.license = "MIT"
11
12
 
12
13
  spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
13
14
 
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.1
4
+ version: 0.3.6
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-07-25 00:00:00.000000000 Z
11
+ date: 2020-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -137,8 +137,8 @@ files:
137
137
  - lib/tdc/generators/configurable_generator.rb
138
138
  - lib/tdc/generators/definition_resolvable.rb
139
139
  - lib/tdc/generators/definition_sourcable.rb
140
+ - lib/tdc/generators/generation_context.rb
140
141
  - lib/tdc/generators/generator_base.rb
141
- - lib/tdc/generators/singular_generator.rb
142
142
  - lib/tdc/generators/standard_generator.rb
143
143
  - lib/tdc/in_memory_data_definition.rb
144
144
  - lib/tdc/missing_override_error.rb
@@ -146,7 +146,8 @@ files:
146
146
  - lib/tdc/with_indifferent_access_decorator.rb
147
147
  - tdc.gemspec
148
148
  homepage: https://github.com/nulogy/tdc
149
- licenses: []
149
+ licenses:
150
+ - MIT
150
151
  metadata:
151
152
  homepage_uri: https://github.com/nulogy/tdc
152
153
  changelog_uri: https://github.com/nulogy/tdc/blob/master/CHANGELOG.md
@@ -1,39 +0,0 @@
1
- module Tdc
2
- module Generators
3
- #
4
- # Abstract class for defining generators that define a single model instance.
5
- #
6
- # See also StandardGenerator.
7
- #
8
- class SingularGenerator < Tdc::Generators::ConfigurableGenerator
9
- def with_definition(additional_definitions)
10
- @additional_definitions = additional_definitions.stringify_keys.reject { |_, v| v == :missing_definition }
11
-
12
- self
13
- end
14
-
15
- def generate
16
- configure_instance_definition(singular_instance_definition.merge(additional_definitions))
17
-
18
- run_resolvers_and_generate_instance
19
- end
20
-
21
- private
22
-
23
- def additional_definitions
24
- @additional_definitions || {}
25
- end
26
-
27
- def singular_instance_definition
28
- all_instance_definitions = instance_definitions
29
-
30
- if all_instance_definitions.many?
31
- raise Tdc::FatalError, "A singular generator only generates a single model instance"
32
- end
33
-
34
- # Delete the tag so that the models do not need to filter it out.
35
- all_instance_definitions.first.except("tag")
36
- end
37
- end
38
- end
39
- end