reflekt 1.0.9 → 1.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/accessor.rb +33 -27
- data/lib/action.rb +108 -71
- data/lib/action_stack.rb +29 -31
- data/lib/clone.rb +10 -12
- data/lib/config.rb +44 -41
- data/lib/control.rb +44 -48
- data/lib/experiment.rb +63 -74
- data/lib/meta.rb +50 -48
- data/lib/meta/array_meta.rb +26 -30
- data/lib/meta/boolean_meta.rb +17 -19
- data/lib/meta/float_meta.rb +17 -19
- data/lib/meta/integer_meta.rb +17 -19
- data/lib/meta/null_meta.rb +19 -19
- data/lib/meta/string_meta.rb +17 -19
- data/lib/meta_builder.rb +74 -74
- data/lib/reflection.rb +91 -91
- data/lib/reflekt.rb +160 -126
- data/lib/renderer.rb +27 -30
- data/lib/rule.rb +33 -33
- data/lib/rule_set.rb +64 -65
- data/lib/rule_set_aggregator.rb +191 -193
- data/lib/rules/array_rule.rb +77 -73
- data/lib/rules/boolean_rule.rb +29 -35
- data/lib/rules/float_rule.rb +42 -46
- data/lib/rules/integer_rule.rb +42 -46
- data/lib/rules/null_rule.rb +30 -30
- data/lib/rules/string_rule.rb +54 -62
- data/lib/web/index.html +3 -4
- metadata +17 -3
data/lib/meta/float_meta.rb
CHANGED
@@ -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
|
-
|
6
|
+
def initialize()
|
7
|
+
@type = :float
|
8
|
+
@value = nil
|
9
|
+
end
|
7
10
|
|
8
|
-
|
9
|
-
@value
|
11
|
+
##
|
12
|
+
# @param value [Float]
|
13
|
+
##
|
14
|
+
def load(value)
|
15
|
+
@value = value
|
16
|
+
end
|
10
17
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
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
|
data/lib/meta/integer_meta.rb
CHANGED
@@ -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
|
-
|
6
|
+
def initialize()
|
7
|
+
@type = :int
|
8
|
+
@value = nil
|
9
|
+
end
|
7
10
|
|
8
|
-
|
9
|
-
@value
|
11
|
+
##
|
12
|
+
# @param value [Integer]
|
13
|
+
##
|
14
|
+
def load(value)
|
15
|
+
@value = value
|
16
|
+
end
|
10
17
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
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
|
data/lib/meta/null_meta.rb
CHANGED
@@ -13,24 +13,24 @@
|
|
13
13
|
require_relative '../meta'
|
14
14
|
|
15
15
|
module Reflekt
|
16
|
-
class NullMeta < Meta
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
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
|
data/lib/meta/string_meta.rb
CHANGED
@@ -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
|
-
|
6
|
+
def initialize()
|
7
|
+
@type = :string
|
8
|
+
@length = nil
|
9
|
+
end
|
7
10
|
|
8
|
-
|
9
|
-
@
|
11
|
+
##
|
12
|
+
# @param value [String]
|
13
|
+
##
|
14
|
+
def load(value)
|
15
|
+
@length = value.length
|
16
|
+
end
|
10
17
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
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
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
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
|
-
|
48
|
-
|
51
|
+
return meta
|
52
|
+
|
49
53
|
end
|
50
54
|
|
51
|
-
|
55
|
+
##
|
56
|
+
# Create meta for multiple values.
|
57
|
+
#
|
58
|
+
# @param values
|
59
|
+
##
|
60
|
+
def self.create_many(values)
|
52
61
|
|
53
|
-
|
62
|
+
meta = []
|
54
63
|
|
55
|
-
|
56
|
-
|
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
|
-
|
68
|
+
return meta
|
63
69
|
|
64
|
-
values.each do |value|
|
65
|
-
meta << self.create(value)
|
66
70
|
end
|
67
71
|
|
68
|
-
|
69
|
-
|
70
|
-
|
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
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
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
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
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
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
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
|
-
|
115
|
-
reflection
|
116
|
-
|
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
|
-
|
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
|