reflekt 1.0.9 → 1.0.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,28 +1,26 @@
1
1
  require_relative '../meta'
2
2
 
3
3
  module Reflekt
4
- class FloatMeta < Meta
4
+ class FloatMeta < Meta
5
5
 
6
- def initialize()
6
+ def initialize()
7
+ @type = :float
8
+ @value = nil
9
+ end
7
10
 
8
- @type = :float
9
- @value = nil
11
+ ##
12
+ # @param value [Float]
13
+ ##
14
+ def load(value)
15
+ @value = value
16
+ end
10
17
 
11
- end
12
-
13
- ##
14
- # @param value [Float]
15
- ##
16
- def load(value)
17
- @value = value
18
- end
18
+ def serialize()
19
+ {
20
+ :type => @type,
21
+ :value => @value
22
+ }
23
+ end
19
24
 
20
- def serialize()
21
- {
22
- :type => @type,
23
- :value => @value
24
- }
25
25
  end
26
-
27
- end
28
26
  end
@@ -1,28 +1,26 @@
1
1
  require_relative '../meta'
2
2
 
3
3
  module Reflekt
4
- class IntegerMeta < Meta
4
+ class IntegerMeta < Meta
5
5
 
6
- def initialize()
6
+ def initialize()
7
+ @type = :int
8
+ @value = nil
9
+ end
7
10
 
8
- @type = :int
9
- @value = nil
11
+ ##
12
+ # @param value [Integer]
13
+ ##
14
+ def load(value)
15
+ @value = value
16
+ end
10
17
 
11
- end
12
-
13
- ##
14
- # @param value [Integer]
15
- ##
16
- def load(value)
17
- @value = value
18
- end
18
+ def serialize()
19
+ {
20
+ :type => @type,
21
+ :value => @value
22
+ }
23
+ end
19
24
 
20
- def serialize()
21
- {
22
- :type => @type,
23
- :value => @value
24
- }
25
25
  end
26
-
27
- end
28
26
  end
@@ -13,24 +13,24 @@
13
13
  require_relative '../meta'
14
14
 
15
15
  module Reflekt
16
- class NullMeta < Meta
17
-
18
- def initialize()
19
- @type = :null
20
- end
21
-
22
- ##
23
- # @param value [NilClass]
24
- ##
25
- def load(value)
26
- # No need to load a value for null meta.
16
+ class NullMeta < Meta
17
+
18
+ def initialize()
19
+ @type = :null
20
+ end
21
+
22
+ ##
23
+ # @param value [NilClass]
24
+ ##
25
+ def load(value)
26
+ # No need to load a value for null meta.
27
+ end
28
+
29
+ def serialize()
30
+ {
31
+ :type => @type,
32
+ }
33
+ end
34
+
27
35
  end
28
-
29
- def serialize()
30
- {
31
- :type => @type,
32
- }
33
- end
34
-
35
- end
36
36
  end
@@ -1,28 +1,26 @@
1
1
  require_relative '../meta'
2
2
 
3
3
  module Reflekt
4
- class StringMeta < Meta
4
+ class StringMeta < Meta
5
5
 
6
- def initialize()
6
+ def initialize()
7
+ @type = :string
8
+ @length = nil
9
+ end
7
10
 
8
- @type = :string
9
- @length = nil
11
+ ##
12
+ # @param value [String]
13
+ ##
14
+ def load(value)
15
+ @length = value.length
16
+ end
10
17
 
11
- end
12
-
13
- ##
14
- # @param value [String]
15
- ##
16
- def load(value)
17
- @length = value.length
18
- end
18
+ def serialize()
19
+ {
20
+ :type => @type,
21
+ :length => @length
22
+ }
23
+ end
19
24
 
20
- def serialize()
21
- {
22
- :type => @type,
23
- :length => @length
24
- }
25
25
  end
26
-
27
- end
28
26
  end
data/lib/meta_builder.rb CHANGED
@@ -6,95 +6,95 @@
6
6
  ################################################################################
7
7
 
8
8
  require_relative 'meta'
9
- # Require all meta.
9
+ # Require all meta from the meta directory.
10
10
  Dir[File.join(__dir__, 'meta', '*.rb')].each { |file| require_relative file }
11
11
 
12
12
  module Reflekt
13
- class MetaBuilder
14
-
15
- ##
16
- # Create meta type for matching data type.
17
- #
18
- # @flow
19
- # 1. First return basic type
20
- # 2. Then return custom type
21
- # 3. Then return "nil" type
22
- #
23
- # @param value
24
- ##
25
- def self.create(value)
26
-
27
- meta = nil
28
- data_type = value.class.to_s
29
-
30
- case data_type
31
- when "Array"
32
- meta = ArrayMeta.new()
33
- when "TrueClass", "FalseClass"
34
- meta = BooleanMeta.new()
35
- when "Float"
36
- meta = FloatMeta.new()
37
- when "Integer"
38
- meta = IntegerMeta.new()
39
- when "String"
40
- meta = StringMeta.new()
41
- else
42
- unless value.nil?
43
- meta = ObjectMeta.new()
13
+ class MetaBuilder
14
+
15
+ ##
16
+ # Create meta type for matching data type.
17
+ #
18
+ # @logic
19
+ # 1. First return basic type
20
+ # 2. Then return custom type
21
+ # 3. Then return "nil" type
22
+ #
23
+ # @param value [Dynamic] Any input or output.
24
+ ##
25
+ def self.create(value)
26
+
27
+ meta = nil
28
+ data_type = value.class.to_s
29
+
30
+ case data_type
31
+ when "Array"
32
+ meta = ArrayMeta.new()
33
+ when "TrueClass", "FalseClass"
34
+ meta = BooleanMeta.new()
35
+ when "Float"
36
+ meta = FloatMeta.new()
37
+ when "Integer"
38
+ meta = IntegerMeta.new()
39
+ when "String"
40
+ meta = StringMeta.new()
41
+ else
42
+ unless value.nil?
43
+ meta = ObjectMeta.new()
44
+ end
45
+ end
46
+
47
+ unless meta.nil?
48
+ meta.load(value)
44
49
  end
45
- end
46
50
 
47
- unless meta.nil?
48
- meta.load(value)
51
+ return meta
52
+
49
53
  end
50
54
 
51
- return meta
55
+ ##
56
+ # Create meta for multiple values.
57
+ #
58
+ # @param values
59
+ ##
60
+ def self.create_many(values)
52
61
 
53
- end
62
+ meta = []
54
63
 
55
- ##
56
- # Create meta for multiple values.
57
- #
58
- # @param values
59
- ##
60
- def self.create_many(values)
64
+ values.each do |value|
65
+ meta << self.create(value)
66
+ end
61
67
 
62
- meta = []
68
+ return meta
63
69
 
64
- values.each do |value|
65
- meta << self.create(value)
66
70
  end
67
71
 
68
- return meta
69
-
70
- end
72
+ ##
73
+ # @param data_type [Type]
74
+ ##
75
+ def self.data_type_to_meta_type(value)
76
+
77
+ data_type = value.class
78
+
79
+ meta_types = {
80
+ Array => :array,
81
+ TrueClass => :bool,
82
+ FalseClass => :bool,
83
+ Float => :float,
84
+ Integer => :int,
85
+ NilClass => :null,
86
+ String => :string
87
+ }
88
+
89
+ if meta_types.key? data_type
90
+ return meta_types[data_type]
91
+ elsif value.nil?
92
+ return nil
93
+ else
94
+ return :object
95
+ end
71
96
 
72
- ##
73
- # @param data_type [Type]
74
- ##
75
- def self.data_type_to_meta_type(value)
76
-
77
- data_type = value.class
78
-
79
- meta_types = {
80
- Array => :array,
81
- TrueClass => :bool,
82
- FalseClass => :bool,
83
- Float => :float,
84
- Integer => :int,
85
- NilClass => :null,
86
- String => :string
87
- }
88
-
89
- if meta_types.key? data_type
90
- return meta_types[data_type]
91
- elsif value.nil?
92
- return nil
93
- else
94
- return :object
95
97
  end
96
98
 
97
99
  end
98
-
99
- end
100
100
  end
data/lib/reflection.rb CHANGED
@@ -21,103 +21,103 @@ require_relative 'clone'
21
21
  require_relative 'meta_builder'
22
22
 
23
23
  module Reflekt
24
- class Reflection
25
-
26
- attr_reader :status
27
-
28
- ##
29
- # Create a reflection.
30
- #
31
- # @param action [Action] The Action that created this Reflection.
32
- # @param number [Integer] Multiple Reflections can be created per Action.
33
- # @param aggregator [RuleSetAggregator] The aggregated RuleSet for this class/method.
34
- ##
35
- def initialize(action, number, aggregator)
36
-
37
- @action = action
38
- @unique_id = action.unique_id + number
39
- @number = number
40
-
41
- # Dependency.
42
- @aggregator = aggregator
43
-
44
- # Caller.
45
- @klass = action.klass
46
- @method = action.method
47
-
48
- # Metadata.
49
- @inputs = nil
50
- @output = nil
51
-
52
- # Clone the action's calling object.
53
- # TODO: Abstract away into Clone class.
54
- @clone = action.caller_object.clone
55
-
56
- # Result.
57
- @status = :pass
58
- @time = Time.now.to_i
59
- @message = nil
60
-
61
- end
62
-
63
- ##
64
- # Reflect on a method.
65
- #
66
- # Create a shadow action.
67
- # @param *args [Dynamic] The method's arguments.
68
- ##
69
- def reflect(*args)
70
- # Implemented by Control and Experiment.
71
- end
24
+ class Reflection
25
+ include LitCLI
26
+
27
+ attr_reader :status
28
+
29
+ ##
30
+ # Create a reflection.
31
+ #
32
+ # @param action [Action] The Action that created this Reflection.
33
+ # @param number [Integer] Multiple Reflections can be created per Action.
34
+ # @param aggregator [RuleSetAggregator] The aggregated RuleSet for this class/method.
35
+ ##
36
+ def initialize(action, number, aggregator)
37
+ @action = action
38
+ @reflection_id = action.unique_id + number
39
+ @number = number
40
+
41
+ # Dependency.
42
+ @aggregator = aggregator
43
+
44
+ # Caller.
45
+ @klass = action.klass
46
+ @method = action.method
47
+
48
+ # Metadata.
49
+ @inputs = nil
50
+ @output = nil
51
+
52
+ # Clone the action's calling object.
53
+ # TODO: Abstract away into Clone class.
54
+ @clone = action.caller_object.clone
55
+
56
+ # Result.
57
+ @status = :pass
58
+ @time = Time.now.to_i
59
+ @message = nil
60
+ end
72
61
 
73
- ##
74
- # Get the results of the reflection.
75
- #
76
- # @keys
77
- # - eid [Integer] Execution ID
78
- # - aid [Integer] Action ID
79
- # - rid [Integer] Reflection ID
80
- # - num [Integer] Reflection number
81
- #
82
- # @return [Hash] Reflection metadata.
83
- ##
84
- def serialize()
85
-
86
- # Create execution ID from the ID of the first action in the ActionStack.
87
- execution_id = @action.unique_id
88
- unless @action.base.nil?
89
- execution_id = @action.base.unique_id
62
+ ##
63
+ # Reflect on a method.
64
+ #
65
+ # Create a shadow action.
66
+ # @param *args [Dynamic] The method's arguments.
67
+ ##
68
+ def reflect(*args)
69
+ # Implemented by Control and Experiment.
90
70
  end
91
71
 
92
- # Build reflection.
93
- reflection = {
94
- :eid => execution_id,
95
- :aid => @action.unique_id,
96
- :rid => @unique_id,
97
- :num => @number,
98
- :time => @time,
99
- :class => @klass,
100
- :method => @method,
101
- :status => @status,
102
- :message => @message,
103
- :inputs => nil,
104
- :output => nil,
105
- }
106
-
107
- unless @inputs.nil?
108
- reflection[:inputs] = []
109
- @inputs.each do |meta|
110
- reflection[:inputs] << meta.serialize()
72
+ ##
73
+ # Get the results of the reflection.
74
+ #
75
+ # @keys
76
+ # - eid [Integer] Execution ID
77
+ # - aid [Integer] Action ID
78
+ # - rid [Integer] Reflection ID
79
+ # - num [Integer] Reflection number
80
+ #
81
+ # @return [Hash] Reflection metadata.
82
+ ##
83
+ def serialize()
84
+ # Create execution ID from the ID of the first action in the ActionStack.
85
+ execution_id = @action.unique_id
86
+ unless @action.base.nil?
87
+ execution_id = @action.base.unique_id
111
88
  end
112
- end
113
89
 
114
- unless @output.nil?
115
- reflection[:output] = @output.serialize()
116
- end
90
+ # Build reflection.
91
+ reflection = {
92
+ :eid => execution_id,
93
+ :aid => @action.unique_id,
94
+ :rid => @reflection_id,
95
+ :num => @number,
96
+ :time => @time,
97
+ :class => @klass,
98
+ :method => @method,
99
+ :status => @status,
100
+ :message => @message,
101
+ :inputs => nil,
102
+ :output => nil,
103
+ }
104
+
105
+ # TODO: After the last experiment for an action is completed, serialize()
106
+ # appears to be called twice. Possibly due to inheritance.
107
+ 🔥"> Save meta for #{@method}()", :save, :meta, @klass
108
+
109
+ unless @inputs.nil?
110
+ reflection[:inputs] = []
111
+ @inputs.each do |meta|
112
+ meta.nil? ? nil : reflection[:inputs] << meta.serialize()
113
+ end
114
+ end
117
115
 
118
- return reflection
116
+ unless @output.nil?
117
+ reflection[:output] = @output.serialize()
118
+ end
119
119
 
120
+ return reflection
121
+ end
120
122
  end
121
-
122
- end
123
123
  end