reflekt 1.0.4 → 1.0.9
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 → accessor.rb} +2 -0
- data/lib/{Execution.rb → action.rb} +14 -12
- data/lib/action_stack.rb +46 -0
- data/lib/{Clone.rb → clone.rb} +6 -4
- data/lib/{Config.rb → config.rb} +3 -0
- data/lib/{Control.rb → control.rb} +16 -12
- data/lib/{Reflection.rb → experiment.rb} +16 -90
- data/lib/{Meta.rb → meta.rb} +7 -5
- data/lib/meta/{ArrayMeta.rb → array_meta.rb} +3 -1
- data/lib/meta/{BooleanMeta.rb → boolean_meta.rb} +3 -1
- data/lib/meta/{FloatMeta.rb → float_meta.rb} +3 -1
- data/lib/meta/{IntegerMeta.rb → integer_meta.rb} +3 -1
- data/lib/meta/{NullMeta.rb → null_meta.rb} +4 -2
- data/lib/meta/object_meta.rb +35 -0
- data/lib/meta/{StringMeta.rb → string_meta.rb} +3 -1
- data/lib/{MetaBuilder.rb → meta_builder.rb} +21 -5
- data/lib/reflection.rb +123 -0
- data/lib/{Reflekt.rb → reflekt.rb} +42 -42
- data/lib/{Renderer.rb → renderer.rb} +2 -0
- data/lib/{Rule.rb → rule.rb} +3 -1
- data/lib/{RuleSet.rb → rule_set.rb} +5 -3
- data/lib/{Aggregator.rb → rule_set_aggregator.rb} +29 -18
- data/lib/rules/{ArrayRule.rb → array_rule.rb} +3 -1
- data/lib/rules/{BooleanRule.rb → boolean_rule.rb} +3 -1
- data/lib/rules/{FloatRule.rb → float_rule.rb} +3 -1
- data/lib/rules/{IntegerRule.rb → integer_rule.rb} +3 -1
- data/lib/rules/{NullRule.rb → null_rule.rb} +5 -6
- data/lib/rules/object_rule.rb +42 -0
- data/lib/rules/{StringRule.rb → string_rule.rb} +3 -1
- data/lib/web/bundle.js +2 -2
- data/lib/web/package-lock.json +3 -3
- data/lib/web/package.json +1 -1
- data/lib/web/server.js +5 -5
- metadata +32 -29
- data/lib/ShadowStack.rb +0 -44
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ed0b66e3e9110822e6d14ba1a77fc5627b40edea4223d4252fd30ea4853047c
|
4
|
+
data.tar.gz: 39990e22a2f9ddac9382a8b960b10ead0b81598db3bf86eac4a1c499182e065b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 48497c5c451bde6860039fb9570f77a4bd0a9fd4b889d497d9c06079a9e852f3f426e42f01c5480c6bf621f4ba90179e9f95022fcd5e223f3b1da6718936e871
|
7
|
+
data.tar.gz: 4e1f58483092d4f7f626878303060c0527ff0838ab244f4abc9e3f5b5772af19c95a5a5e86e1a2d6361027efa80882ead7dafee544698bf895555a7086a63d97
|
@@ -8,6 +8,7 @@
|
|
8
8
|
# - @@reflekt_skipped_methods on the instance's singleton class
|
9
9
|
################################################################################
|
10
10
|
|
11
|
+
module Reflekt
|
11
12
|
class Accessor
|
12
13
|
|
13
14
|
attr_accessor :config
|
@@ -35,3 +36,4 @@ class Accessor
|
|
35
36
|
end
|
36
37
|
|
37
38
|
end
|
39
|
+
end
|
@@ -1,13 +1,14 @@
|
|
1
1
|
################################################################################
|
2
|
-
# A shadow
|
2
|
+
# A shadow action.
|
3
3
|
#
|
4
4
|
# @hierachy
|
5
|
-
# 1.
|
5
|
+
# 1. Action <- YOU ARE HERE
|
6
6
|
# 2. Reflection
|
7
7
|
# 3. Meta
|
8
8
|
################################################################################
|
9
9
|
|
10
|
-
|
10
|
+
module Reflekt
|
11
|
+
class Action
|
11
12
|
|
12
13
|
attr_accessor :unique_id
|
13
14
|
attr_accessor :caller_object
|
@@ -19,17 +20,17 @@ class Execution
|
|
19
20
|
attr_accessor :parent
|
20
21
|
attr_accessor :child
|
21
22
|
attr_accessor :control
|
22
|
-
attr_accessor :
|
23
|
+
attr_accessor :experiments
|
23
24
|
attr_accessor :is_reflecting
|
24
25
|
attr_accessor :is_base
|
25
26
|
|
26
27
|
##
|
27
|
-
# Create
|
28
|
+
# Create Action.
|
28
29
|
#
|
29
30
|
# @param object [Object] The calling object.
|
30
31
|
# @param method [Symbol] The calling method.
|
31
|
-
# @param reflect_amount [Integer] The number of
|
32
|
-
# @param stack [
|
32
|
+
# @param reflect_amount [Integer] The number of experiments to create per action.
|
33
|
+
# @param stack [ActionStack] The shadow action call stack.
|
33
34
|
##
|
34
35
|
def initialize(caller_object, method, reflect_amount, stack)
|
35
36
|
|
@@ -51,7 +52,7 @@ class Execution
|
|
51
52
|
|
52
53
|
# Reflections.
|
53
54
|
@control = nil
|
54
|
-
@
|
55
|
+
@experiments = Array.new(reflect_amount)
|
55
56
|
|
56
57
|
# State.
|
57
58
|
if @stack.peek() == nil
|
@@ -64,12 +65,12 @@ class Execution
|
|
64
65
|
|
65
66
|
end
|
66
67
|
|
67
|
-
def
|
68
|
-
@
|
68
|
+
def has_empty_experiments?
|
69
|
+
@experiments.include? nil
|
69
70
|
end
|
70
71
|
|
71
72
|
##
|
72
|
-
# Is the
|
73
|
+
# Is the Action currently reflecting methods?
|
73
74
|
##
|
74
75
|
def is_reflecting?
|
75
76
|
@is_reflecting
|
@@ -79,10 +80,11 @@ class Execution
|
|
79
80
|
if is_reflecting?
|
80
81
|
return false
|
81
82
|
end
|
82
|
-
if
|
83
|
+
if has_empty_experiments?
|
83
84
|
return false
|
84
85
|
end
|
85
86
|
return true
|
86
87
|
end
|
87
88
|
|
88
89
|
end
|
90
|
+
end
|
data/lib/action_stack.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
################################################################################
|
2
|
+
# Track the actions in a shadow call stack.
|
3
|
+
#
|
4
|
+
# @pattern Stack
|
5
|
+
################################################################################
|
6
|
+
|
7
|
+
module Reflekt
|
8
|
+
class ActionStack
|
9
|
+
|
10
|
+
def initialize()
|
11
|
+
@bottom = nil
|
12
|
+
@top = nil
|
13
|
+
end
|
14
|
+
|
15
|
+
def peek()
|
16
|
+
@top
|
17
|
+
end
|
18
|
+
|
19
|
+
def base()
|
20
|
+
@bottom
|
21
|
+
end
|
22
|
+
|
23
|
+
##
|
24
|
+
# Place Action at the top of stack.
|
25
|
+
#
|
26
|
+
# @param action [Action] The action to place.
|
27
|
+
# @return [Action] The placed action.
|
28
|
+
##
|
29
|
+
def push(action)
|
30
|
+
|
31
|
+
# Place first action at bottom of stack.
|
32
|
+
if @bottom.nil?
|
33
|
+
@bottom = action
|
34
|
+
# Connect subsequent actions to each other.
|
35
|
+
else
|
36
|
+
@top.parent = action
|
37
|
+
action.child = @top
|
38
|
+
end
|
39
|
+
|
40
|
+
# Place action at top of stack.
|
41
|
+
@top = action
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
data/lib/{Clone.rb → clone.rb}
RENAMED
@@ -7,17 +7,18 @@
|
|
7
7
|
# on object, not indirectly through clone which results in "undefined method".
|
8
8
|
#
|
9
9
|
# @hierachy
|
10
|
-
# 1.
|
10
|
+
# 1. Action
|
11
11
|
# 2. Reflection
|
12
12
|
# 3. Clone <- YOU ARE HERE
|
13
13
|
################################################################################
|
14
14
|
|
15
|
+
module Reflekt
|
15
16
|
class Clone
|
16
17
|
|
17
|
-
def initialize(
|
18
|
+
def initialize(action)
|
18
19
|
|
19
|
-
# Clone the
|
20
|
-
@caller_object_clone =
|
20
|
+
# Clone the action's calling object.
|
21
|
+
@caller_object_clone = action.caller_object.clone
|
21
22
|
|
22
23
|
# TODO: Clone any other instances that this clone references.
|
23
24
|
# TODO: Replace clone's references to these new instances.
|
@@ -29,3 +30,4 @@ class Clone
|
|
29
30
|
end
|
30
31
|
|
31
32
|
end
|
33
|
+
end
|
data/lib/{Config.rb → config.rb}
RENAMED
@@ -1,3 +1,4 @@
|
|
1
|
+
module Reflekt
|
1
2
|
class Config
|
2
3
|
|
3
4
|
attr_accessor :enabled
|
@@ -27,6 +28,7 @@ class Config
|
|
27
28
|
:int => [IntegerRule],
|
28
29
|
:float => [FloatRule],
|
29
30
|
:null => [NullRule],
|
31
|
+
:object => [ObjectRule],
|
30
32
|
:string => [StringRule]
|
31
33
|
}
|
32
34
|
|
@@ -40,3 +42,4 @@ class Config
|
|
40
42
|
end
|
41
43
|
|
42
44
|
end
|
45
|
+
end
|
@@ -2,13 +2,13 @@
|
|
2
2
|
# A shapshot of real data.
|
3
3
|
#
|
4
4
|
# @note
|
5
|
-
# A control's @number
|
5
|
+
# A control's @number will always be 0.
|
6
6
|
#
|
7
7
|
# @nomenclature
|
8
8
|
# args, inputs/output and meta represent different stages of a value.
|
9
9
|
#
|
10
10
|
# @hierachy
|
11
|
-
# 1.
|
11
|
+
# 1. Action
|
12
12
|
# 2. Control <- YOU ARE HERE
|
13
13
|
# 3. Meta
|
14
14
|
#
|
@@ -18,43 +18,46 @@
|
|
18
18
|
# - :error [Symbol] The control reflection produces a system error.
|
19
19
|
################################################################################
|
20
20
|
|
21
|
-
|
22
|
-
|
21
|
+
require_relative 'reflection'
|
22
|
+
require_relative 'meta_builder'
|
23
23
|
|
24
|
+
module Reflekt
|
24
25
|
class Control < Reflection
|
25
26
|
|
26
27
|
##
|
27
28
|
# Reflect on a method.
|
28
29
|
#
|
29
|
-
#
|
30
|
+
# Create a shadow action.
|
30
31
|
# @param *args [Dynamic] The method's arguments.
|
31
32
|
##
|
32
33
|
def reflect(*args)
|
33
34
|
|
34
|
-
# Get
|
35
|
+
# Get trained rule sets.
|
35
36
|
input_rule_sets = @aggregator.get_input_rule_sets(@klass, @method)
|
36
37
|
output_rule_set = @aggregator.get_output_rule_set(@klass, @method)
|
37
38
|
|
39
|
+
# Fail when no trained rule sets.
|
40
|
+
if input_rule_sets.nil?
|
41
|
+
@status = :fail
|
42
|
+
end
|
43
|
+
|
38
44
|
# When arguments exist.
|
39
45
|
unless args.size == 0
|
40
46
|
|
41
|
-
#
|
47
|
+
# Validate arguments against trained rule sets.
|
42
48
|
unless input_rule_sets.nil?
|
43
|
-
|
44
|
-
# Validate arguments against aggregated rule sets.
|
45
49
|
unless @aggregator.test_inputs(args, input_rule_sets)
|
46
50
|
@status = :fail
|
47
51
|
end
|
48
|
-
|
49
52
|
end
|
50
53
|
|
51
54
|
# Create metadata for each argument.
|
52
|
-
# TODO: Create metadata for other inputs such as
|
55
|
+
# TODO: Create metadata for other inputs such as instance variables.
|
53
56
|
@inputs = MetaBuilder.create_many(args)
|
54
57
|
|
55
58
|
end
|
56
59
|
|
57
|
-
# Action method with
|
60
|
+
# Action method with real arguments.
|
58
61
|
begin
|
59
62
|
|
60
63
|
# Run reflection.
|
@@ -79,3 +82,4 @@ class Control < Reflection
|
|
79
82
|
end
|
80
83
|
|
81
84
|
end
|
85
|
+
end
|
@@ -2,15 +2,14 @@
|
|
2
2
|
# A snapshot of random data.
|
3
3
|
#
|
4
4
|
# @note
|
5
|
-
# A reflection's random
|
6
|
-
# as well as as the arg type being inputted into the current control reflection.
|
5
|
+
# A reflection's random values are generated from aggregated control rule sets.
|
7
6
|
#
|
8
7
|
# @nomenclature
|
9
8
|
# args, inputs/output and meta represent different stages of a value.
|
10
9
|
#
|
11
10
|
# @hierachy
|
12
|
-
# 1.
|
13
|
-
# 2.
|
11
|
+
# 1. Action
|
12
|
+
# 2. Experiment <- YOU ARE HERE
|
14
13
|
# 3. Meta
|
15
14
|
#
|
16
15
|
# @status
|
@@ -19,52 +18,16 @@
|
|
19
18
|
# - :error [Symbol] The control reflection produces a system error.
|
20
19
|
################################################################################
|
21
20
|
|
22
|
-
|
23
|
-
|
21
|
+
require_relative 'reflection'
|
22
|
+
require_relative 'meta_builder'
|
24
23
|
|
25
|
-
|
26
|
-
|
27
|
-
attr_reader :status
|
28
|
-
|
29
|
-
##
|
30
|
-
# Create a Reflection.
|
31
|
-
#
|
32
|
-
# @param execution [Execution] The Execution that created this Reflection.
|
33
|
-
# @param number [Integer] Multiple Reflections can be created per Execution.
|
34
|
-
# @param aggregator [Aggregator] The aggregated RuleSet for this class/method.
|
35
|
-
##
|
36
|
-
def initialize(execution, number, aggregator)
|
37
|
-
|
38
|
-
@execution = execution
|
39
|
-
@unique_id = execution.unique_id + number
|
40
|
-
@number = number
|
41
|
-
|
42
|
-
# Dependency.
|
43
|
-
@aggregator = aggregator
|
44
|
-
|
45
|
-
# Caller.
|
46
|
-
@klass = execution.klass
|
47
|
-
@method = execution.method
|
48
|
-
|
49
|
-
# Metadata.
|
50
|
-
@inputs = nil
|
51
|
-
@output = nil
|
52
|
-
|
53
|
-
# Clone the execution's calling object.
|
54
|
-
# TODO: Abstract away into Clone class.
|
55
|
-
@clone = execution.caller_object.clone
|
56
|
-
|
57
|
-
# Result.
|
58
|
-
@status = :pass
|
59
|
-
@time = Time.now.to_i
|
60
|
-
@message = nil
|
61
|
-
|
62
|
-
end
|
24
|
+
module Reflekt
|
25
|
+
class Experiment < Reflection
|
63
26
|
|
64
27
|
##
|
65
28
|
# Reflect on a method.
|
66
29
|
#
|
67
|
-
#
|
30
|
+
# Create a shadow action.
|
68
31
|
# @param *args [Dynamic] The method's arguments.
|
69
32
|
##
|
70
33
|
def reflect(*args)
|
@@ -73,6 +36,11 @@ class Reflection
|
|
73
36
|
input_rule_sets = @aggregator.get_input_rule_sets(@klass, @method)
|
74
37
|
output_rule_set = @aggregator.get_output_rule_set(@klass, @method)
|
75
38
|
|
39
|
+
# Fail when no trained rule sets.
|
40
|
+
if input_rule_sets.nil?
|
41
|
+
@status = :fail
|
42
|
+
end
|
43
|
+
|
76
44
|
# When arguments exist.
|
77
45
|
unless args.size == 0
|
78
46
|
|
@@ -82,12 +50,12 @@ class Reflection
|
|
82
50
|
end
|
83
51
|
|
84
52
|
# Create metadata for each argument.
|
85
|
-
# TODO: Create metadata for other inputs such as
|
53
|
+
# TODO: Create metadata for other inputs such as instance variables.
|
86
54
|
@inputs = MetaBuilder.create_many(args)
|
87
55
|
|
88
56
|
end
|
89
57
|
|
90
|
-
# Action method with
|
58
|
+
# Action method with random arguments.
|
91
59
|
begin
|
92
60
|
|
93
61
|
# Run reflection.
|
@@ -138,47 +106,5 @@ class Reflection
|
|
138
106
|
|
139
107
|
end
|
140
108
|
|
141
|
-
|
142
|
-
# Get the results of the reflection.
|
143
|
-
#
|
144
|
-
# @return [Hash] Reflection metadata.
|
145
|
-
##
|
146
|
-
def serialize()
|
147
|
-
|
148
|
-
# The ID of the first execution in the ShadowStack.
|
149
|
-
base_id = nil
|
150
|
-
unless @execution.base == nil
|
151
|
-
base_id = @execution.base.unique_id
|
152
|
-
end
|
153
|
-
|
154
|
-
# Build reflection.
|
155
|
-
reflection = {
|
156
|
-
:base_id => base_id,
|
157
|
-
:exe_id => @execution.unique_id,
|
158
|
-
:ref_id => @unique_id,
|
159
|
-
:ref_num => @number,
|
160
|
-
:time => @time,
|
161
|
-
:class => @klass,
|
162
|
-
:method => @method,
|
163
|
-
:status => @status,
|
164
|
-
:message => @message,
|
165
|
-
:inputs => nil,
|
166
|
-
:output => nil,
|
167
|
-
}
|
168
|
-
|
169
|
-
unless @inputs.nil?
|
170
|
-
reflection[:inputs] = []
|
171
|
-
@inputs.each do |meta|
|
172
|
-
reflection[:inputs] << meta.serialize()
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
unless @output.nil?
|
177
|
-
reflection[:output] = @output.serialize()
|
178
|
-
end
|
179
|
-
|
180
|
-
return reflection
|
181
|
-
|
182
|
-
end
|
183
|
-
|
109
|
+
end
|
184
110
|
end
|
data/lib/{Meta.rb → meta.rb}
RENAMED
@@ -5,18 +5,19 @@
|
|
5
5
|
# @see lib/meta for each meta.
|
6
6
|
#
|
7
7
|
# @hierachy
|
8
|
-
# 1.
|
8
|
+
# 1. Action
|
9
9
|
# 2. Reflection
|
10
10
|
# 3. Meta <- YOU ARE HERE
|
11
11
|
################################################################################
|
12
12
|
|
13
|
+
module Reflekt
|
13
14
|
class Meta
|
14
15
|
|
15
16
|
##
|
16
17
|
# Each meta defines its type.
|
17
18
|
##
|
18
19
|
def initialize()
|
19
|
-
@type =
|
20
|
+
@type = :null
|
20
21
|
end
|
21
22
|
|
22
23
|
##
|
@@ -28,12 +29,12 @@ class Meta
|
|
28
29
|
end
|
29
30
|
|
30
31
|
##
|
31
|
-
# Each meta serializes metadata.
|
32
|
-
#
|
33
32
|
# @return [Hash]
|
34
33
|
##
|
35
34
|
def serialize()
|
36
|
-
{
|
35
|
+
{
|
36
|
+
:type => @type
|
37
|
+
}
|
37
38
|
end
|
38
39
|
|
39
40
|
##############################################################################
|
@@ -69,3 +70,4 @@ class Meta
|
|
69
70
|
end
|
70
71
|
|
71
72
|
end
|
73
|
+
end
|