evt-transform 0.1.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/transform.rb +6 -0
- data/lib/transform/controls.rb +8 -0
- data/lib/transform/controls/no_format.rb +26 -0
- data/lib/transform/controls/no_format_methods.rb +30 -0
- data/lib/transform/controls/no_transform.rb +16 -0
- data/lib/transform/controls/no_transform_methods.rb +18 -0
- data/lib/transform/controls/raw_data.rb +9 -0
- data/lib/transform/controls/subject.rb +49 -0
- data/lib/transform/controls/subject_instance_receives_class.rb +37 -0
- data/lib/transform/controls/text.rb +9 -0
- data/lib/transform/log.rb +9 -0
- data/lib/transform/read.rb +61 -0
- data/lib/transform/transform.rb +105 -0
- data/lib/transform/write.rb +50 -0
- metadata +85 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0eb5f9cee74f7a41101a61f683318734da02d87e
|
4
|
+
data.tar.gz: ebae2488a51203863f88c4d2b879e6b13089e418
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1ae466e13cfdfac031f55ffddfdea634c92a1e58ea031f09df904934e8203a5a9f4484fa3136ca2338dd60ed832adc152177029587d027eebd73ddad28e84586
|
7
|
+
data.tar.gz: 4d41b452e432ec11ac0d0e15df4b64f9173b7a7582bcc9ee729650b8a6d56dc436cc3a3e4a7d9aa7d4e16db480dbb537664054300110710d61f208a93fa5233f
|
data/lib/transform.rb
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
require 'transform/controls/text'
|
2
|
+
require 'transform/controls/raw_data'
|
3
|
+
require 'transform/controls/subject'
|
4
|
+
require 'transform/controls/subject_instance_receives_class'
|
5
|
+
require 'transform/controls/no_transform'
|
6
|
+
require 'transform/controls/no_transform_methods'
|
7
|
+
require 'transform/controls/no_format'
|
8
|
+
require 'transform/controls/no_format_methods'
|
@@ -0,0 +1,26 @@
|
|
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
|
@@ -0,0 +1,30 @@
|
|
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
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Transform
|
2
|
+
module Controls
|
3
|
+
module Subject
|
4
|
+
def self.example
|
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
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Transform
|
2
|
+
module Controls
|
3
|
+
module Subject
|
4
|
+
module InstanceReceivesClass
|
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
|
+
module Transformer
|
19
|
+
def self.some_format
|
20
|
+
SomeFormat
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.instance(raw_data, cls)
|
24
|
+
Struct.new(:raw_data, :cls).new(raw_data, cls)
|
25
|
+
end
|
26
|
+
|
27
|
+
module SomeFormat
|
28
|
+
def self.read(text)
|
29
|
+
text
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module Transform
|
2
|
+
module Read
|
3
|
+
extend Transform
|
4
|
+
|
5
|
+
def self.mode
|
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
|
+
|
18
|
+
logger.trace { "Reading (Format Name: #{format_name.inspect})" }
|
19
|
+
logger.trace(tags: [:data, :raw_data]) { raw_data.pretty_inspect }
|
20
|
+
|
21
|
+
format = format(cls, format_name)
|
22
|
+
|
23
|
+
assure_mode(format, mode)
|
24
|
+
raw_data = format.read raw_data
|
25
|
+
|
26
|
+
transformed = instance(raw_data, cls)
|
27
|
+
|
28
|
+
logger.info { "Read (Format Name: #{format_name.inspect})" }
|
29
|
+
logger.debug(tags: [:data, :transformed]) { transformed.pretty_inspect }
|
30
|
+
|
31
|
+
transformed
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.instance(raw_data, cls)
|
35
|
+
logger.trace { "Transforming raw data to instance" }
|
36
|
+
logger.trace(tags: [:data, :raw_data]) { raw_data.pretty_inspect }
|
37
|
+
|
38
|
+
transformer = transformer(cls)
|
39
|
+
assure_mode(transformer, intermediate)
|
40
|
+
|
41
|
+
method = transformer.method(:instance)
|
42
|
+
|
43
|
+
instance = nil
|
44
|
+
case method.parameters.length
|
45
|
+
when 1
|
46
|
+
instance = transformer.instance(raw_data)
|
47
|
+
when 2
|
48
|
+
instance = transformer.instance(raw_data, cls)
|
49
|
+
end
|
50
|
+
|
51
|
+
logger.debug { "Transformed raw data to instance" }
|
52
|
+
logger.debug(tags: [:data, :instance]) { instance.pretty_inspect }
|
53
|
+
|
54
|
+
instance
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.logger
|
58
|
+
@logger ||= Log.get(self)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
module Transform
|
2
|
+
extend self
|
3
|
+
|
4
|
+
class Error < RuntimeError; end
|
5
|
+
|
6
|
+
def format(subject, format_name)
|
7
|
+
transformer = transformer(subject)
|
8
|
+
|
9
|
+
assure_format(format_name, transformer)
|
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
|
+
subject_const.const_get(:Transformer)
|
26
|
+
end
|
27
|
+
|
28
|
+
def subject_const(subject)
|
29
|
+
[Module, Class].include?(subject.class) ? subject : subject.class
|
30
|
+
end
|
31
|
+
|
32
|
+
def assure_transformer(subject_const)
|
33
|
+
unless transformer_const?(subject_const)
|
34
|
+
raise Error, "#{subject_const.name} doesn't have a `Transformer' namespace"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def transformer?(subject)
|
39
|
+
subject_const = subject_const(subject)
|
40
|
+
transformer_const?(subject_const)
|
41
|
+
end
|
42
|
+
|
43
|
+
def transformer_const?(subject_const)
|
44
|
+
subject_const.const_defined?(:Transformer)
|
45
|
+
end
|
46
|
+
|
47
|
+
def assure_format(format_name, transformer)
|
48
|
+
unless format_accessor?(format_name, transformer)
|
49
|
+
raise Error, "#{transformer.name} does not implement `#{format_name}'"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def format_accessor?(format_name, transformer)
|
54
|
+
transformer.respond_to?(format_name)
|
55
|
+
end
|
56
|
+
|
57
|
+
def format?(format_name, transformer)
|
58
|
+
format = get_format(format_name, transformer)
|
59
|
+
!!format
|
60
|
+
end
|
61
|
+
|
62
|
+
def assure_mode(format, mode)
|
63
|
+
unless mode?(format, mode)
|
64
|
+
raise Error, "#{format.name} does not implement `#{mode}'"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def mode?(format, mode)
|
69
|
+
format.respond_to?(mode)
|
70
|
+
end
|
71
|
+
|
72
|
+
def intermediate?(transformer, intermediate_name)
|
73
|
+
transformer.respond_to?(intermediate_name)
|
74
|
+
end
|
75
|
+
|
76
|
+
def implemented?(subject, format_name)
|
77
|
+
subject_const = subject_const(subject)
|
78
|
+
|
79
|
+
unless transformer_const?(subject_const)
|
80
|
+
return false
|
81
|
+
end
|
82
|
+
|
83
|
+
transformer = get_transformer(subject_const)
|
84
|
+
|
85
|
+
unless intermediate?(transformer, intermediate)
|
86
|
+
return false
|
87
|
+
end
|
88
|
+
|
89
|
+
unless format_accessor?(format_name, transformer)
|
90
|
+
return false
|
91
|
+
end
|
92
|
+
|
93
|
+
unless format?(format_name, transformer)
|
94
|
+
return false
|
95
|
+
end
|
96
|
+
|
97
|
+
format = get_format(format_name, transformer)
|
98
|
+
|
99
|
+
unless mode?(format, mode)
|
100
|
+
return false
|
101
|
+
end
|
102
|
+
|
103
|
+
true
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Transform
|
2
|
+
module Write
|
3
|
+
extend Transform
|
4
|
+
|
5
|
+
def self.mode
|
6
|
+
:write
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.intermediate
|
10
|
+
:raw_data
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.call(instance, format_name)
|
14
|
+
logger.trace { "Writing (Format Name: #{format_name.inspect})" }
|
15
|
+
logger.trace(tags: [:data, :instance]) { instance.pretty_inspect }
|
16
|
+
|
17
|
+
format = format(instance, format_name)
|
18
|
+
|
19
|
+
raw_data = raw_data(instance)
|
20
|
+
|
21
|
+
assure_mode(format, mode)
|
22
|
+
|
23
|
+
transformed = format.write(raw_data)
|
24
|
+
|
25
|
+
logger.info { "Wrote (Format Name: #{format_name.inspect})" }
|
26
|
+
logger.debug(tags: [:data, :transformed]) { transformed.pretty_inspect }
|
27
|
+
|
28
|
+
transformed
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.raw_data(instance)
|
32
|
+
logger.trace { "Transforming instance to raw data" }
|
33
|
+
logger.trace(tags: [:data, :instance]) { instance.pretty_inspect }
|
34
|
+
|
35
|
+
transformer = transformer(instance)
|
36
|
+
assure_mode(transformer, intermediate)
|
37
|
+
|
38
|
+
raw_data = transformer.raw_data(instance)
|
39
|
+
|
40
|
+
logger.debug { "Transformed to raw data" }
|
41
|
+
logger.debug(tags: [:data, :raw_data]) { raw_data.pretty_inspect }
|
42
|
+
|
43
|
+
raw_data
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.logger
|
47
|
+
@logger ||= Log.get(self)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: evt-transform
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- The Eventide Project
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-12-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: evt-log
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: ntl-test_bench
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: " "
|
42
|
+
email: opensource@eventide-project.org
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files: []
|
46
|
+
files:
|
47
|
+
- lib/transform.rb
|
48
|
+
- lib/transform/controls.rb
|
49
|
+
- lib/transform/controls/no_format.rb
|
50
|
+
- lib/transform/controls/no_format_methods.rb
|
51
|
+
- lib/transform/controls/no_transform.rb
|
52
|
+
- lib/transform/controls/no_transform_methods.rb
|
53
|
+
- lib/transform/controls/raw_data.rb
|
54
|
+
- lib/transform/controls/subject.rb
|
55
|
+
- lib/transform/controls/subject_instance_receives_class.rb
|
56
|
+
- lib/transform/controls/text.rb
|
57
|
+
- lib/transform/log.rb
|
58
|
+
- lib/transform/read.rb
|
59
|
+
- lib/transform/transform.rb
|
60
|
+
- lib/transform/write.rb
|
61
|
+
homepage: https://github.com/eventide-project/transform
|
62
|
+
licenses:
|
63
|
+
- MIT
|
64
|
+
metadata: {}
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: 2.3.3
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
requirements: []
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 2.5.2
|
82
|
+
signing_key:
|
83
|
+
specification_version: 4
|
84
|
+
summary: Common interface for object and format transformation, and transformer discovery
|
85
|
+
test_files: []
|