reflekt 1.0.3 → 1.0.8
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 +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 -1
- data/lib/{Control.rb → control.rb} +16 -12
- data/lib/experiment.rb +83 -0
- 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/{StringMeta.rb → string_meta.rb} +3 -1
- data/lib/{MetaBuilder.rb → meta_builder.rb} +4 -2
- data/lib/reflection.rb +150 -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/{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 +30 -29
- data/lib/Reflection.rb +0 -193
- 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: 8fca22a79b9c2f962c5bd4583de7c8f35a27e5a350503aac4888d8072a2e843c
|
4
|
+
data.tar.gz: bf44e0c83c0e1e281b1aab9ecc3b86728152941484995167803d81de28e53170
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e59ad6e1e3a7e293d904da162c40478ca34a8b6daf0abefd3a0e0e58e525a249cccfd3d36602b0550925efb048e4df4a500c33865e93ebb7a13d2cbb7fea83a
|
7
|
+
data.tar.gz: b5762a194aa4c94849c4e3540cb9e51e2ea1feb779f51a6f4b424aa4c25aec7410137fb0d5a4ca9c1891ee4b350b58e6a7f34b81d4c57fd0f279a31b509f5b1e
|
@@ -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
|
@@ -31,7 +32,7 @@ class Config
|
|
31
32
|
}
|
32
33
|
|
33
34
|
# An absolute path to the directory that contains the output directory.
|
34
|
-
# Defaults to current
|
35
|
+
# Defaults to current action path.
|
35
36
|
@output_path = nil
|
36
37
|
|
37
38
|
# Name of output directory.
|
@@ -40,3 +41,4 @@ class Config
|
|
40
41
|
end
|
41
42
|
|
42
43
|
end
|
44
|
+
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
|
data/lib/experiment.rb
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
################################################################################
|
2
|
+
# A snapshot of random data.
|
3
|
+
#
|
4
|
+
# @note
|
5
|
+
# A reflection's random values are generated from aggregated control rule sets.
|
6
|
+
#
|
7
|
+
# @nomenclature
|
8
|
+
# args, inputs/output and meta represent different stages of a value.
|
9
|
+
#
|
10
|
+
# @hierachy
|
11
|
+
# 1. Action
|
12
|
+
# 2. Experiment <- YOU ARE HERE
|
13
|
+
# 3. Meta
|
14
|
+
#
|
15
|
+
# @status
|
16
|
+
# - :pass [Symbol] The reflection passes the rules.
|
17
|
+
# - :fail [Symbol] The reflection fails the rules or produces a system error.
|
18
|
+
# - :error [Symbol] The control reflection produces a system error.
|
19
|
+
################################################################################
|
20
|
+
|
21
|
+
require_relative 'reflection'
|
22
|
+
require_relative 'meta_builder'
|
23
|
+
|
24
|
+
module Reflekt
|
25
|
+
class Experiment < Reflection
|
26
|
+
|
27
|
+
##
|
28
|
+
# Reflect on a method.
|
29
|
+
#
|
30
|
+
# Create a shadow action.
|
31
|
+
# @param *args [Dynamic] The method's arguments.
|
32
|
+
##
|
33
|
+
def reflect(*args)
|
34
|
+
|
35
|
+
# Get aggregated rule sets.
|
36
|
+
input_rule_sets = @aggregator.get_input_rule_sets(@klass, @method)
|
37
|
+
output_rule_set = @aggregator.get_output_rule_set(@klass, @method)
|
38
|
+
|
39
|
+
# Fail when no trained rule sets.
|
40
|
+
if input_rule_sets.nil?
|
41
|
+
@status = :fail
|
42
|
+
end
|
43
|
+
|
44
|
+
# When arguments exist.
|
45
|
+
unless args.size == 0
|
46
|
+
|
47
|
+
# Create random arguments from aggregated rule sets.
|
48
|
+
unless input_rule_sets.nil?
|
49
|
+
args = randomize(args, input_rule_sets)
|
50
|
+
end
|
51
|
+
|
52
|
+
# Create metadata for each argument.
|
53
|
+
# TODO: Create metadata for other inputs such as instance variables.
|
54
|
+
@inputs = MetaBuilder.create_many(args)
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
# Action method with random arguments.
|
59
|
+
begin
|
60
|
+
|
61
|
+
# Run reflection.
|
62
|
+
output = @clone.send(@method, *args)
|
63
|
+
@output = MetaBuilder.create(output)
|
64
|
+
|
65
|
+
# Validate output against aggregated control rule sets.
|
66
|
+
unless output_rule_set.nil?
|
67
|
+
unless @aggregator.test_output(output, output_rule_set)
|
68
|
+
@status = :fail
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
# When a system error occurs.
|
73
|
+
rescue StandardError => message
|
74
|
+
|
75
|
+
@status = :fail
|
76
|
+
@message = message
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
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
|