evt-transform 0.1.3.0 → 0.2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8dfc383c07eccd30d0da3059af8ace4292e879e967506b496b877df82a150c16
4
- data.tar.gz: 931175ac1c40ccc04218f928a01fd915913c7d32a365173f592a0a9a2d923168
3
+ metadata.gz: 7260f7bfa8857baec7819abfc066e1ca82351426370080050a79eff83045b0ca
4
+ data.tar.gz: d93f0bf14cfdea3e7bfb1b067bc42280680ba08ac51713f4d849aa1d0dca414e
5
5
  SHA512:
6
- metadata.gz: b3ab2ded9cb2d24e4127510e14d37bcd057eb74162a4aa39dd02b501fbe8093837d861ada503bdd6057065b53fd7223d62df27bc85b9be402c14c4a936218230
7
- data.tar.gz: 39b6cfc738ce60cf2679669ed8b56f505235645abcb1af10ab29f367a42d71142c79857482fba02c43b2b5fc179993f539902ff74c965d9007bb5f5ade334240
6
+ metadata.gz: 61fd991c0d43026f027a7326fa229168eeb3ac9bedb83239bffb965a9606ab99002b2fa1350f9038d1f22eaa909bddbcdf9df1e7d9140b5de105030aff13b495
7
+ data.tar.gz: e1147a06fd830aac80c7860fdfd6e0e7d8d97fd05537d205df579c43d6ee939816eaa85e364dd59fb5988d8bd39fcca05c9a41c24b1d138a4ad5228c1d725b44
@@ -1,4 +1,5 @@
1
1
  require 'log'
2
+ require 'reflect'
2
3
 
3
4
  require 'transform/log'
4
5
  require 'transform/transform'
@@ -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 Transformer
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
- 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
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 = Subject
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
@@ -2,41 +2,44 @@ module Transform
2
2
  module Read
3
3
  extend Transform
4
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
-
5
+ def self.call(input, format_name, cls)
18
6
  logger.trace { "Reading (Format Name: #{format_name.inspect})" }
19
- logger.trace(tags: [:data, :raw_data]) { raw_data.pretty_inspect }
7
+ logger.trace(tags: [:data, :input]) { input.pretty_inspect }
20
8
 
21
- format = format(cls, format_name)
9
+ transformer_reflection = transformer_reflection(cls)
22
10
 
23
- assure_mode(format, mode)
24
- raw_data = format.read raw_data
11
+ format_reflection = transformer_reflection.get(format_name)
25
12
 
26
- transformed = instance(raw_data, cls)
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, :transformed]) { transformed.pretty_inspect }
18
+ logger.debug(tags: [:data, :output]) { instance.pretty_inspect }
30
19
 
31
- transformed
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
- transformer = transformer(cls)
39
- assure_mode(transformer, intermediate)
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
@@ -0,0 +1,5 @@
1
+ test retry
2
+
3
+ need to raise expected version error
4
+
5
+ expected version raises when version number is mismatched
@@ -1,113 +1,40 @@
1
1
  module Transform
2
2
  extend self
3
3
 
4
- class Error < RuntimeError; end
4
+ Error = Class.new(RuntimeError)
5
5
 
6
- def format(subject, format_name)
7
- transformer = transformer(subject)
6
+ def transformer_reflection(subject)
7
+ subject_constant = Reflect.subject_constant(subject)
8
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
- 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
- def transform_const?(subject_const)
52
- subject_const.constants.any?{ |c| c.to_sym == :Transform }
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
- def format?(format_name, transformer)
66
- format = get_format(format_name, transformer)
67
- !!format
15
+ Reflect.(subject, transformer_name, strict: true)
68
16
  end
69
17
 
70
- def assure_mode(format, mode)
71
- unless mode?(format, mode)
72
- raise Error, "#{format.name} does not implement `#{mode}'"
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 mode?(format, mode)
77
- format.respond_to?(mode)
28
+ def transform_const?(subject_constant)
29
+ Reflect.constant?(subject_constant, :Transform)
78
30
  end
79
31
 
80
- def intermediate?(transformer, intermediate_name)
81
- transformer.respond_to?(intermediate_name)
32
+ def transformer_const?(subject_constant)
33
+ Reflect.constant?(subject_constant, :Transformer)
82
34
  end
83
35
 
84
- def implemented?(subject, format_name)
85
- subject_const = subject_const(subject)
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
@@ -2,40 +2,41 @@ module Transform
2
2
  module Write
3
3
  extend Transform
4
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)
5
+ def self.call(input, format_name)
14
6
  logger.trace { "Writing (Format Name: #{format_name.inspect})" }
15
- logger.trace(tags: [:data, :instance]) { instance.pretty_inspect }
7
+ logger.trace(tags: [:data, :input]) { input.pretty_inspect }
16
8
 
17
- format = format(instance, format_name)
9
+ transformer_reflection = transformer_reflection(input)
18
10
 
19
- raw_data = raw_data(instance)
11
+ format_reflection = transformer_reflection.get(format_name)
20
12
 
21
- assure_mode(format, mode)
13
+ raw_data = raw_data(input, transformer_reflection)
22
14
 
23
- transformed = format.write(raw_data)
15
+ output = format_reflection.(:write, raw_data)
24
16
 
25
17
  logger.info { "Wrote (Format Name: #{format_name.inspect})" }
26
- logger.debug(tags: [:data, :transformed]) { transformed.pretty_inspect }
18
+ logger.debug(tags: [:data, :output]) { output.pretty_inspect }
27
19
 
28
- transformed
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
- transformer = transformer(instance)
36
- assure_mode(transformer, intermediate)
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
- raw_data = transformer.raw_data(instance)
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.1.3.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-03-25 00:00:00.000000000 Z
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