evt-transform 0.1.3.0 → 0.2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/transform.rb +1 -0
- data/lib/transform/controls.rb +0 -2
- data/lib/transform/controls/no_transform_methods.rb +14 -1
- data/lib/transform/controls/subject.rb +7 -43
- data/lib/transform/controls/subject/transformer.rb +45 -1
- data/lib/transform/read.rb +32 -26
- data/lib/transform/retry_test.rb +5 -0
- data/lib/transform/transform.rb +21 -94
- data/lib/transform/write.rb +34 -20
- metadata +17 -4
- data/lib/transform/controls/no_format.rb +0 -26
- data/lib/transform/controls/no_format_methods.rb +0 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7260f7bfa8857baec7819abfc066e1ca82351426370080050a79eff83045b0ca
|
4
|
+
data.tar.gz: d93f0bf14cfdea3e7bfb1b067bc42280680ba08ac51713f4d849aa1d0dca414e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61fd991c0d43026f027a7326fa229168eeb3ac9bedb83239bffb965a9606ab99002b2fa1350f9038d1f22eaa909bddbcdf9df1e7d9140b5de105030aff13b495
|
7
|
+
data.tar.gz: e1147a06fd830aac80c7860fdfd6e0e7d8d97fd05537d205df579c43d6ee939816eaa85e364dd59fb5988d8bd39fcca05c9a41c24b1d138a4ad5228c1d725b44
|
data/lib/transform.rb
CHANGED
data/lib/transform/controls.rb
CHANGED
@@ -6,5 +6,3 @@ require 'transform/controls/subject/transform'
|
|
6
6
|
require 'transform/controls/subject/transformer'
|
7
7
|
require 'transform/controls/no_transformer'
|
8
8
|
require 'transform/controls/no_transform_methods'
|
9
|
-
require 'transform/controls/no_format'
|
10
|
-
require 'transform/controls/no_format_methods'
|
@@ -2,7 +2,20 @@ module Transform
|
|
2
2
|
module Controls
|
3
3
|
module NoTransformMethods
|
4
4
|
class Example
|
5
|
-
module
|
5
|
+
module Transform
|
6
|
+
def self.some_format
|
7
|
+
SomeFormat
|
8
|
+
end
|
9
|
+
|
10
|
+
module SomeFormat
|
11
|
+
def self.write(raw_data)
|
12
|
+
Controls::Text.example
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.read(text)
|
16
|
+
Controls::RawData.example
|
17
|
+
end
|
18
|
+
end
|
6
19
|
end
|
7
20
|
end
|
8
21
|
|
@@ -1,49 +1,13 @@
|
|
1
1
|
module Transform
|
2
2
|
module Controls
|
3
3
|
module Subject
|
4
|
-
|
5
|
-
instance = example_class.new
|
6
|
-
instance.some_attribute = Controls::RawData.example
|
7
|
-
instance
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.example_class
|
11
|
-
Example
|
12
|
-
end
|
13
|
-
|
14
|
-
class Example
|
15
|
-
attr_accessor :some_attribute
|
16
|
-
|
17
|
-
def ==(other)
|
18
|
-
other.some_attribute == self.some_attribute
|
19
|
-
end
|
20
|
-
|
21
|
-
module Transformer
|
22
|
-
def self.some_format
|
23
|
-
SomeFormat
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.instance(raw_data)
|
27
|
-
instance = Example.new
|
28
|
-
instance.some_attribute = raw_data
|
29
|
-
instance
|
30
|
-
end
|
31
|
-
|
32
|
-
def self.raw_data(instance)
|
33
|
-
instance.some_attribute
|
34
|
-
end
|
35
|
-
|
36
|
-
module SomeFormat
|
37
|
-
def self.write(raw_data)
|
38
|
-
Controls::Text.example
|
39
|
-
end
|
40
|
-
|
41
|
-
def self.read(text)
|
42
|
-
Controls::RawData.example
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
4
|
+
Transformer = Subject
|
47
5
|
end
|
48
6
|
end
|
49
7
|
end
|
8
|
+
module Transform
|
9
|
+
module Controls
|
10
|
+
Subject = Transform::Controls::Subject::Transformer
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
@@ -1,7 +1,51 @@
|
|
1
1
|
module Transform
|
2
2
|
module Controls
|
3
3
|
module Subject
|
4
|
-
Transformer
|
4
|
+
module Transformer
|
5
|
+
def self.example
|
6
|
+
instance = example_class.new
|
7
|
+
instance.some_attribute = Controls::RawData.example
|
8
|
+
instance
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.example_class
|
12
|
+
Example
|
13
|
+
end
|
14
|
+
|
15
|
+
class Example
|
16
|
+
attr_accessor :some_attribute
|
17
|
+
|
18
|
+
def ==(other)
|
19
|
+
other.some_attribute == self.some_attribute
|
20
|
+
end
|
21
|
+
|
22
|
+
module Transformer
|
23
|
+
def self.some_format
|
24
|
+
SomeFormat
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.instance(raw_data)
|
28
|
+
instance = Example.new
|
29
|
+
instance.some_attribute = raw_data
|
30
|
+
instance
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.raw_data(instance)
|
34
|
+
instance.some_attribute
|
35
|
+
end
|
36
|
+
|
37
|
+
module SomeFormat
|
38
|
+
def self.write(raw_data)
|
39
|
+
Controls::Text.example
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.read(text)
|
43
|
+
Controls::RawData.example
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
5
49
|
end
|
6
50
|
end
|
7
51
|
end
|
data/lib/transform/read.rb
CHANGED
@@ -2,41 +2,44 @@ module Transform
|
|
2
2
|
module Read
|
3
3
|
extend Transform
|
4
4
|
|
5
|
-
def self.
|
6
|
-
:read
|
7
|
-
end
|
8
|
-
|
9
|
-
def self.intermediate
|
10
|
-
:instance
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.call(raw_data, format_name, cls)
|
14
|
-
if format_name.instance_of?(Class) && cls.instance_of?(Symbol)
|
15
|
-
cls, format_name = format_name, cls
|
16
|
-
end
|
17
|
-
|
5
|
+
def self.call(input, format_name, cls)
|
18
6
|
logger.trace { "Reading (Format Name: #{format_name.inspect})" }
|
19
|
-
logger.trace(tags: [:data, :
|
7
|
+
logger.trace(tags: [:data, :input]) { input.pretty_inspect }
|
20
8
|
|
21
|
-
|
9
|
+
transformer_reflection = transformer_reflection(cls)
|
22
10
|
|
23
|
-
|
24
|
-
raw_data = format.read raw_data
|
11
|
+
format_reflection = transformer_reflection.get(format_name)
|
25
12
|
|
26
|
-
|
13
|
+
raw_data = format_reflection.(:read, input)
|
14
|
+
|
15
|
+
instance = instance(raw_data, cls, transformer_reflection)
|
27
16
|
|
28
17
|
logger.info { "Read (Format Name: #{format_name.inspect})" }
|
29
|
-
logger.debug(tags: [:data, :
|
18
|
+
logger.debug(tags: [:data, :output]) { instance.pretty_inspect }
|
30
19
|
|
31
|
-
|
20
|
+
instance
|
32
21
|
end
|
33
22
|
|
34
|
-
def self.instance(raw_data, cls)
|
23
|
+
def self.instance(raw_data, cls, transformer_reflection=nil)
|
35
24
|
logger.trace { "Transforming raw data to instance" }
|
36
25
|
logger.trace(tags: [:data, :raw_data]) { raw_data.pretty_inspect }
|
37
26
|
|
38
|
-
|
39
|
-
|
27
|
+
if transformer_reflection.nil?
|
28
|
+
transformer_reflection = transformer_reflection(cls)
|
29
|
+
end
|
30
|
+
|
31
|
+
transformer = transformer_reflection.constant
|
32
|
+
|
33
|
+
instance = get_instance(transformer, raw_data, cls)
|
34
|
+
|
35
|
+
logger.debug { "Transformed raw data to instance" }
|
36
|
+
logger.debug(tags: [:data, :instance]) { instance.pretty_inspect }
|
37
|
+
|
38
|
+
instance
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.get_instance(transformer, raw_data, cls)
|
42
|
+
assure_instance_method(transformer)
|
40
43
|
|
41
44
|
method = transformer.method(:instance)
|
42
45
|
|
@@ -48,12 +51,15 @@ module Transform
|
|
48
51
|
instance = transformer.instance(raw_data, cls)
|
49
52
|
end
|
50
53
|
|
51
|
-
logger.debug { "Transformed raw data to instance" }
|
52
|
-
logger.debug(tags: [:data, :instance]) { instance.pretty_inspect }
|
53
|
-
|
54
54
|
instance
|
55
55
|
end
|
56
56
|
|
57
|
+
def self.assure_instance_method(transformer)
|
58
|
+
unless transformer.respond_to?(:instance)
|
59
|
+
raise Error, "#{transformer.name} does not implement `instance'"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
57
63
|
def self.logger
|
58
64
|
@logger ||= Log.get(self)
|
59
65
|
end
|
data/lib/transform/transform.rb
CHANGED
@@ -1,113 +1,40 @@
|
|
1
1
|
module Transform
|
2
2
|
extend self
|
3
3
|
|
4
|
-
|
4
|
+
Error = Class.new(RuntimeError)
|
5
5
|
|
6
|
-
def
|
7
|
-
|
6
|
+
def transformer_reflection(subject)
|
7
|
+
subject_constant = Reflect.subject_constant(subject)
|
8
8
|
|
9
|
-
|
10
|
-
get_format(format_name, transformer)
|
11
|
-
end
|
12
|
-
|
13
|
-
def get_format(format_name, transformer)
|
14
|
-
transformer.send(format_name)
|
15
|
-
end
|
16
|
-
|
17
|
-
def transformer(subject)
|
18
|
-
subject_const = subject_const(subject)
|
19
|
-
|
20
|
-
assure_transformer(subject_const)
|
21
|
-
get_transformer(subject_const)
|
22
|
-
end
|
23
|
-
|
24
|
-
def get_transformer(subject_const)
|
25
|
-
if transformer_const?(subject_const)
|
26
|
-
return subject_const.const_get(:Transformer)
|
27
|
-
elsif transform_const?(subject_const)
|
28
|
-
return subject_const.const_get(:Transform)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def subject_const(subject)
|
33
|
-
[Module, Class].include?(subject.class) ? subject : subject.class
|
34
|
-
end
|
35
|
-
|
36
|
-
def assure_transformer(subject_const)
|
37
|
-
return if transform_const?(subject_const) || transformer_const?(subject_const)
|
38
|
-
|
39
|
-
raise Error, "#{subject_const.name} doesn't have a `Transformer' or 'Transform' namespace"
|
40
|
-
end
|
41
|
-
|
42
|
-
def transformer?(subject)
|
43
|
-
subject_const = subject_const(subject)
|
44
|
-
transformer_const?(subject_const)
|
45
|
-
end
|
46
|
-
|
47
|
-
def transformer_const?(subject_const)
|
48
|
-
subject_const.constants.any?{ |c| c.to_sym == :Transformer }
|
49
|
-
end
|
9
|
+
transformer_name = transformer_name(subject_constant)
|
50
10
|
|
51
|
-
|
52
|
-
|
53
|
-
end
|
54
|
-
|
55
|
-
def assure_format(format_name, transformer)
|
56
|
-
unless format_accessor?(format_name, transformer)
|
57
|
-
raise Error, "#{transformer.name} does not implement `#{format_name}'"
|
11
|
+
if transformer_name.nil?
|
12
|
+
raise Error, "#{subject_constant.name} doesn't have a Transformer or Transform namespace"
|
58
13
|
end
|
59
|
-
end
|
60
|
-
|
61
|
-
def format_accessor?(format_name, transformer)
|
62
|
-
transformer.respond_to?(format_name)
|
63
|
-
end
|
64
14
|
|
65
|
-
|
66
|
-
format = get_format(format_name, transformer)
|
67
|
-
!!format
|
15
|
+
Reflect.(subject, transformer_name, strict: true)
|
68
16
|
end
|
69
17
|
|
70
|
-
def
|
71
|
-
|
72
|
-
|
18
|
+
def transformer_name(subject_constant)
|
19
|
+
if transform_const?(subject_constant)
|
20
|
+
return :Transform
|
21
|
+
elsif transformer_const?(subject_constant)
|
22
|
+
return :Transformer
|
23
|
+
else
|
24
|
+
return nil
|
73
25
|
end
|
74
26
|
end
|
75
27
|
|
76
|
-
def
|
77
|
-
|
28
|
+
def transform_const?(subject_constant)
|
29
|
+
Reflect.constant?(subject_constant, :Transform)
|
78
30
|
end
|
79
31
|
|
80
|
-
def
|
81
|
-
|
32
|
+
def transformer_const?(subject_constant)
|
33
|
+
Reflect.constant?(subject_constant, :Transformer)
|
82
34
|
end
|
83
35
|
|
84
|
-
def
|
85
|
-
|
86
|
-
|
87
|
-
unless transformer_const?(subject_const)
|
88
|
-
return false
|
89
|
-
end
|
90
|
-
|
91
|
-
transformer = get_transformer(subject_const)
|
92
|
-
|
93
|
-
unless intermediate?(transformer, intermediate)
|
94
|
-
return false
|
95
|
-
end
|
96
|
-
|
97
|
-
unless format_accessor?(format_name, transformer)
|
98
|
-
return false
|
99
|
-
end
|
100
|
-
|
101
|
-
unless format?(format_name, transformer)
|
102
|
-
return false
|
103
|
-
end
|
104
|
-
|
105
|
-
format = get_format(format_name, transformer)
|
106
|
-
|
107
|
-
unless mode?(format, mode)
|
108
|
-
return false
|
109
|
-
end
|
110
|
-
|
111
|
-
true
|
36
|
+
def transformer?(subject)
|
37
|
+
subject_constant = Reflect.subject_constant(subject)
|
38
|
+
transform_const?(subject_constant) || transformer_const?(subject_constant)
|
112
39
|
end
|
113
40
|
end
|
data/lib/transform/write.rb
CHANGED
@@ -2,40 +2,41 @@ module Transform
|
|
2
2
|
module Write
|
3
3
|
extend Transform
|
4
4
|
|
5
|
-
def self.
|
6
|
-
:write
|
7
|
-
end
|
8
|
-
|
9
|
-
def self.intermediate
|
10
|
-
:raw_data
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.call(instance, format_name)
|
5
|
+
def self.call(input, format_name)
|
14
6
|
logger.trace { "Writing (Format Name: #{format_name.inspect})" }
|
15
|
-
logger.trace(tags: [:data, :
|
7
|
+
logger.trace(tags: [:data, :input]) { input.pretty_inspect }
|
16
8
|
|
17
|
-
|
9
|
+
transformer_reflection = transformer_reflection(input)
|
18
10
|
|
19
|
-
|
11
|
+
format_reflection = transformer_reflection.get(format_name)
|
20
12
|
|
21
|
-
|
13
|
+
raw_data = raw_data(input, transformer_reflection)
|
22
14
|
|
23
|
-
|
15
|
+
output = format_reflection.(:write, raw_data)
|
24
16
|
|
25
17
|
logger.info { "Wrote (Format Name: #{format_name.inspect})" }
|
26
|
-
logger.debug(tags: [:data, :
|
18
|
+
logger.debug(tags: [:data, :output]) { output.pretty_inspect }
|
27
19
|
|
28
|
-
|
20
|
+
output
|
29
21
|
end
|
30
22
|
|
31
|
-
def self.raw_data(instance)
|
23
|
+
def self.raw_data(instance, transformer_reflection=nil)
|
32
24
|
logger.trace { "Transforming instance to raw data" }
|
33
25
|
logger.trace(tags: [:data, :instance]) { instance.pretty_inspect }
|
34
26
|
|
35
|
-
|
36
|
-
|
27
|
+
if transformer_reflection.nil?
|
28
|
+
subject_constant = Reflect.subject_constant(instance)
|
29
|
+
transformer_name = transformer_name(subject_constant)
|
30
|
+
|
31
|
+
if transformer_name.nil?
|
32
|
+
raise Error, "#{subject_constant.name} doesn't have a `Transformer' or 'Transform' namespace"
|
33
|
+
end
|
37
34
|
|
38
|
-
|
35
|
+
transformer_reflection = Reflect.(instance, transformer_name, strict: true)
|
36
|
+
end
|
37
|
+
|
38
|
+
transformer = transformer_reflection.constant
|
39
|
+
raw_data = get_raw_data(transformer, instance)
|
39
40
|
|
40
41
|
logger.debug { "Transformed to raw data" }
|
41
42
|
logger.debug(tags: [:data, :raw_data]) { raw_data.pretty_inspect }
|
@@ -43,6 +44,19 @@ module Transform
|
|
43
44
|
raw_data
|
44
45
|
end
|
45
46
|
|
47
|
+
# This is not strictly necessary since Reflection does this
|
48
|
+
# but it provides symmetry with Read, which cannot use Reflection
|
49
|
+
def self.get_raw_data(transformer, instance)
|
50
|
+
assure_raw_data_method(transformer)
|
51
|
+
transformer.raw_data(instance)
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.assure_raw_data_method(transformer)
|
55
|
+
unless transformer.respond_to?(:raw_data)
|
56
|
+
raise Error, "#{transformer.name} does not implement `raw_data'"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
46
60
|
def self.logger
|
47
61
|
@logger ||= Log.get(self)
|
48
62
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: evt-transform
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- The Eventide Project
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-04-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: evt-log
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: evt-reflect
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: test_bench
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -46,8 +60,6 @@ extra_rdoc_files: []
|
|
46
60
|
files:
|
47
61
|
- lib/transform.rb
|
48
62
|
- lib/transform/controls.rb
|
49
|
-
- lib/transform/controls/no_format.rb
|
50
|
-
- lib/transform/controls/no_format_methods.rb
|
51
63
|
- lib/transform/controls/no_transform_methods.rb
|
52
64
|
- lib/transform/controls/no_transformer.rb
|
53
65
|
- lib/transform/controls/raw_data.rb
|
@@ -59,6 +71,7 @@ files:
|
|
59
71
|
- lib/transform/copy.rb
|
60
72
|
- lib/transform/log.rb
|
61
73
|
- lib/transform/read.rb
|
74
|
+
- lib/transform/retry_test.rb
|
62
75
|
- lib/transform/transform.rb
|
63
76
|
- lib/transform/write.rb
|
64
77
|
homepage: https://github.com/eventide-project/transform
|
@@ -1,26 +0,0 @@
|
|
1
|
-
module Transform
|
2
|
-
module Controls
|
3
|
-
module NoFormat
|
4
|
-
class Example
|
5
|
-
module Transformer
|
6
|
-
def self.some_format
|
7
|
-
end
|
8
|
-
|
9
|
-
def self.instance(raw_data)
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.raw_data(instance)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.example
|
18
|
-
Example.new
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.example_class
|
22
|
-
Example
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
module Transform
|
2
|
-
module Controls
|
3
|
-
module NoFormatMethods
|
4
|
-
class Example
|
5
|
-
module Transformer
|
6
|
-
def self.some_format
|
7
|
-
SomeFormat
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.instance(raw_data)
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.raw_data(instance)
|
14
|
-
end
|
15
|
-
|
16
|
-
module SomeFormat
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.example
|
22
|
-
Example.new
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.example_class
|
26
|
-
Example
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|