tdc 0.4.0 → 0.4.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: a574acff7829e69b0f0921e3057ed00ccbf149aa6bc23e77585de0c4372183af
4
- data.tar.gz: b8242f2461ab9eab727e3aca43de8b7ad4f31b45435ce67a4e8cd868893263d4
3
+ metadata.gz: f00288e8e5b9fd0db193bd5cb1f861dc54decc8966acc22a7b3c0ca37107970c
4
+ data.tar.gz: 8e57f9daa09264951dc05b6f0addab100a885dd9ca4de1a49466bf34e97b74a4
5
5
  SHA512:
6
- metadata.gz: 5bfe223f7dbbe91f3b92e0d6582d0964a5a1f309190a3f787dde1c6c7132678f2c3f1d0c0faf442231a6c1462ee43941dd1b03460dd0d5f5135612998df0a59b
7
- data.tar.gz: 056c5002c9fbc2cd94ec5a9de9a06d229a271867a915a486abc316c245499ae8c3f069ef8a1bfb14c10d895b9e2af3b5a5035b8af086c5d3187a3bf7592829a5
6
+ metadata.gz: 998df3b2cec606f557721fef093730ec59c038b492bc66087dea92793c0d5767dae2d2fa6b06edce00aa105e586597f92e71f5dd7624a7fd03ad6819c07a0435
7
+ data.tar.gz: f183c0656d49e69ad0c7834da267d2491ca2a58339a1cd820dd639459f7bfba7cf07a15df9cbe98d9749b1add54a5b03daa4a6815a70650286f52ed954595604
@@ -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,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.4.1] - 2020-08-22
10
+
11
+ - Add the `first` method to `CatalogEntries`
12
+
9
13
  ## [0.4.0] - 2020-08-14
10
14
 
11
15
  #### New Features
@@ -1,31 +1,43 @@
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
- extended_attribute_definitions = keep_extended_attributes(instance_definition)
10
+ extended_attribute_definitions = keep_extended_attributes_from(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")
23
+ def convert_to_standard_attribute(extended_attribute_key)
24
+ extended_attribute_key.gsub(/_(at|date|on)x$/, "_\\1")
19
25
  end
20
26
 
21
27
  def extended_attribute_context
22
28
  Time.zone
23
29
  end
24
30
 
25
- def keep_extended_attributes(instance_definition)
26
- instance_definition.select { |k, _v| /_(at|date|on)x$/ =~ k }
31
+ def extended_attribute?(extended_attribute_key)
32
+ /_(at|date|on)x$/ =~ extended_attribute_key
27
33
  end
28
34
  end
35
+
36
+ private
37
+
38
+ def keep_extended_attributes_from(instance_definition)
39
+ instance_definition.select { |extended_attribute_key, _| extended_attribute?(extended_attribute_key) }
40
+ end
29
41
  end
30
42
  end
31
43
  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
@@ -1,3 +1,3 @@
1
1
  module Tdc
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.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.4.0
4
+ version: 0.4.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-14 00:00:00.000000000 Z
11
+ date: 2020-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport