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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f00288e8e5b9fd0db193bd5cb1f861dc54decc8966acc22a7b3c0ca37107970c
|
4
|
+
data.tar.gz: 8e57f9daa09264951dc05b6f0addab100a885dd9ca4de1a49466bf34e97b74a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 998df3b2cec606f557721fef093730ec59c038b492bc66087dea92793c0d5767dae2d2fa6b06edce00aa105e586597f92e71f5dd7624a7fd03ad6819c07a0435
|
7
|
+
data.tar.gz: f183c0656d49e69ad0c7834da267d2491ca2a58339a1cd820dd639459f7bfba7cf07a15df9cbe98d9749b1add54a5b03daa4a6815a70650286f52ed954595604
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -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 =
|
10
|
+
extended_attribute_definitions = keep_extended_attributes_from(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(
|
18
|
-
|
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
|
26
|
-
|
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
|
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
|
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.4.
|
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-
|
11
|
+
date: 2020-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|