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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e5af4cf8808efaeb9b41e29c925aee883139afaea6fef303f060a91566a101b
|
4
|
+
data.tar.gz: cb877b7821ed829907c52387b5fc04ff3c986f05646170dceb3307cc14a4d648
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6200d9280ccdf2cd5cb1788d80e6795813e5dc7ca398ebca75e507aba2fc8e3bf116ec851f3d103c92eaa1e1a79fd0a6c3f14dc1f59cee74117a8a1f74f60e66
|
7
|
+
data.tar.gz: 9b28f16baeafa725c606c0ea458742f86d0b87cda0e95180658b66598a8a08a0efa46f706214d8e00e98eecfc766eadfafeeb47697cf297f62beef95e2ed452d
|
data/lib/accessor.rb
CHANGED
@@ -1,39 +1,45 @@
|
|
1
1
|
################################################################################
|
2
|
-
# Access variables via one object to avoid polluting the caller
|
2
|
+
# Access variables via one object to avoid polluting the caller's scope.
|
3
3
|
#
|
4
4
|
# @pattern Singleton
|
5
5
|
#
|
6
|
-
# @note
|
6
|
+
# @note Variables not accessed via Accessor:
|
7
7
|
# - @reflekt_counts on the instance
|
8
8
|
# - @@reflekt_skipped_methods on the instance's singleton class
|
9
9
|
################################################################################
|
10
10
|
|
11
11
|
module Reflekt
|
12
|
-
class Accessor
|
13
|
-
|
14
|
-
attr_accessor :config
|
15
|
-
attr_accessor :setup
|
16
|
-
attr_accessor :db
|
17
|
-
attr_accessor :stack
|
18
|
-
attr_accessor :aggregator
|
19
|
-
attr_accessor :renderer
|
20
|
-
attr_accessor :path
|
21
|
-
attr_accessor :output_path
|
22
|
-
attr_accessor :error
|
23
|
-
|
24
|
-
def initialize()
|
25
|
-
|
26
|
-
@config = nil
|
27
|
-
@setup = nil
|
28
|
-
@db = nil
|
29
|
-
@stack = nil
|
30
|
-
@aggregator = nil
|
31
|
-
@renderer = nil
|
32
|
-
@path = nil
|
33
|
-
@output_path = nil
|
34
|
-
@error = false
|
12
|
+
class Accessor
|
35
13
|
|
36
|
-
|
14
|
+
attr_accessor :initialized
|
15
|
+
attr_accessor :counts
|
16
|
+
attr_accessor :error
|
37
17
|
|
38
|
-
|
18
|
+
attr_accessor :config
|
19
|
+
attr_accessor :db
|
20
|
+
attr_accessor :stack
|
21
|
+
attr_accessor :aggregator
|
22
|
+
attr_accessor :renderer
|
23
|
+
|
24
|
+
attr_accessor :package_path
|
25
|
+
attr_accessor :project_path
|
26
|
+
attr_accessor :output_path
|
27
|
+
|
28
|
+
def initialize()
|
29
|
+
@initialized = false
|
30
|
+
@counts = {}
|
31
|
+
@error = nil
|
32
|
+
|
33
|
+
@config = nil
|
34
|
+
@db = nil
|
35
|
+
@stack = nil
|
36
|
+
@aggregator = nil
|
37
|
+
@renderer = nil
|
38
|
+
|
39
|
+
@package_path = nil
|
40
|
+
@project_path = nil
|
41
|
+
@output_path = nil
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
39
45
|
end
|
data/lib/action.rb
CHANGED
@@ -8,83 +8,120 @@
|
|
8
8
|
################################################################################
|
9
9
|
|
10
10
|
module Reflekt
|
11
|
-
class Action
|
12
|
-
|
13
|
-
|
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
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
@
|
62
|
-
|
11
|
+
class Action
|
12
|
+
include LitCLI
|
13
|
+
|
14
|
+
attr_accessor :unique_id
|
15
|
+
attr_accessor :caller_object
|
16
|
+
attr_accessor :caller_id
|
17
|
+
attr_accessor :caller_class
|
18
|
+
attr_accessor :klass
|
19
|
+
attr_accessor :method
|
20
|
+
attr_accessor :base
|
21
|
+
attr_accessor :parent
|
22
|
+
attr_accessor :child
|
23
|
+
attr_accessor :control
|
24
|
+
attr_accessor :experiments
|
25
|
+
attr_accessor :is_actioned
|
26
|
+
attr_accessor :is_reflecting
|
27
|
+
attr_accessor :is_base
|
28
|
+
|
29
|
+
##
|
30
|
+
# Create Action.
|
31
|
+
#
|
32
|
+
# @param object [Object] The calling object.
|
33
|
+
# @param method [Symbol] The calling method.
|
34
|
+
# @param reflect_amount [Integer] The number of experiments to create per action.
|
35
|
+
# @param stack [ActionStack] The shadow action call stack.
|
36
|
+
##
|
37
|
+
def initialize(caller_object, method, config, db, stack, aggregator)
|
38
|
+
@time = Time.now.to_i
|
39
|
+
@unique_id = @time + rand(1..99999)
|
40
|
+
@base = nil
|
41
|
+
@child = nil
|
42
|
+
@parent = nil
|
43
|
+
|
44
|
+
# Dependencies.
|
45
|
+
@db = db
|
46
|
+
@stack = stack
|
47
|
+
@aggregator = aggregator
|
48
|
+
|
49
|
+
# Caller.
|
50
|
+
@caller_object = caller_object
|
51
|
+
@caller_class = caller_object.class
|
52
|
+
@caller_id = caller_object.object_id
|
53
|
+
@klass = @caller_class.to_s.to_sym
|
54
|
+
@method = method
|
55
|
+
|
56
|
+
# Reflections.
|
57
|
+
@control = nil
|
58
|
+
@experiments = Array.new(config.reflect_amount)
|
59
|
+
|
60
|
+
# State.
|
61
|
+
@is_reflecting = false
|
62
|
+
if @stack.peek() == nil
|
63
|
+
@is_base = true
|
64
|
+
else
|
65
|
+
@is_base = false
|
66
|
+
@base = @stack.base()
|
67
|
+
end
|
63
68
|
end
|
64
|
-
@is_reflecting = false
|
65
69
|
|
66
|
-
|
70
|
+
def reflect(*args)
|
67
71
|
|
68
|
-
|
69
|
-
|
70
|
-
end
|
72
|
+
🔥"^ Create control for #{@method}()", :info, :control, @klass
|
73
|
+
@control = Control.new(self, 0, @aggregator)
|
71
74
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
75
|
+
@control.reflect(*args)
|
76
|
+
🔥"> Reflected control for #{@method}(): #{args}", @control.status, :result, @klass
|
77
|
+
|
78
|
+
# Stop reflecting when control fails to execute.
|
79
|
+
unless @control.status == :error
|
80
|
+
|
81
|
+
# Save control.
|
82
|
+
@db.get("controls").push(@control.serialize())
|
83
|
+
@db.get("reflections").push(@control.serialize())
|
84
|
+
|
85
|
+
# Multiple experiments per action.
|
86
|
+
@experiments.each_with_index do |value, index|
|
87
|
+
|
88
|
+
🔥"^ Create experiment ##{index + 1} for #{@method}()", :info, :experiment, @klass
|
89
|
+
experiment = Experiment.new(self, index + 1, @aggregator)
|
90
|
+
@experiments[index] = experiment
|
78
91
|
|
79
|
-
|
80
|
-
|
81
|
-
|
92
|
+
# Reflect experiment.
|
93
|
+
experiment.reflect(*args)
|
94
|
+
Reflekt.increase_count(@caller_object, @method)
|
95
|
+
🔥"> Reflected experiment ##{index + 1} for #{@method}()", experiment.status, :result, @klass
|
96
|
+
|
97
|
+
# Save experiment.
|
98
|
+
@db.get("reflections").push(experiment.serialize())
|
99
|
+
end
|
100
|
+
|
101
|
+
# Save results.
|
102
|
+
@db.write()
|
103
|
+
end
|
82
104
|
end
|
83
|
-
|
84
|
-
|
105
|
+
|
106
|
+
def is_actioned?
|
107
|
+
@is_actioned
|
85
108
|
end
|
86
|
-
return true
|
87
|
-
end
|
88
109
|
|
89
|
-
|
110
|
+
# Is the action currently reflecting methods?
|
111
|
+
def is_reflecting?
|
112
|
+
@is_reflecting
|
113
|
+
end
|
114
|
+
|
115
|
+
def has_empty_experiments?
|
116
|
+
@experiments.include? nil
|
117
|
+
end
|
118
|
+
|
119
|
+
def has_finished_loop?
|
120
|
+
return false if is_actioned? == false
|
121
|
+
return false if is_reflecting?
|
122
|
+
return false if has_empty_experiments?
|
123
|
+
|
124
|
+
true
|
125
|
+
end
|
126
|
+
end
|
90
127
|
end
|
data/lib/action_stack.rb
CHANGED
@@ -5,42 +5,40 @@
|
|
5
5
|
################################################################################
|
6
6
|
|
7
7
|
module Reflekt
|
8
|
-
class ActionStack
|
8
|
+
class ActionStack
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
def peek()
|
16
|
-
@top
|
17
|
-
end
|
18
|
-
|
19
|
-
def base()
|
20
|
-
@bottom
|
21
|
-
end
|
10
|
+
def initialize()
|
11
|
+
@bottom = nil
|
12
|
+
@top = nil
|
13
|
+
end
|
22
14
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
# @param action [Action] The action to place.
|
27
|
-
# @return [Action] The placed action.
|
28
|
-
##
|
29
|
-
def push(action)
|
15
|
+
def peek()
|
16
|
+
@top
|
17
|
+
end
|
30
18
|
|
31
|
-
|
32
|
-
|
33
|
-
@bottom = action
|
34
|
-
# Connect subsequent actions to each other.
|
35
|
-
else
|
36
|
-
@top.parent = action
|
37
|
-
action.child = @top
|
19
|
+
def base()
|
20
|
+
@bottom
|
38
21
|
end
|
39
22
|
|
40
|
-
|
41
|
-
|
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
|
+
# First time? Place action at bottom of stack.
|
31
|
+
if @bottom.nil?
|
32
|
+
@bottom = action
|
33
|
+
# Connect subsequent actions to each other.
|
34
|
+
else
|
35
|
+
@top.parent = action
|
36
|
+
action.child = @top
|
37
|
+
end
|
38
|
+
|
39
|
+
# Place action at top of stack.
|
40
|
+
@top = action
|
41
|
+
end
|
42
42
|
|
43
43
|
end
|
44
|
-
|
45
|
-
end
|
46
44
|
end
|
data/lib/clone.rb
CHANGED
@@ -13,21 +13,19 @@
|
|
13
13
|
################################################################################
|
14
14
|
|
15
15
|
module Reflekt
|
16
|
-
class Clone
|
16
|
+
class Clone
|
17
17
|
|
18
|
-
|
18
|
+
def initialize(action)
|
19
|
+
# Clone the action's calling object.
|
20
|
+
@caller_object_clone = action.caller_object.clone
|
19
21
|
|
20
|
-
|
21
|
-
|
22
|
+
# TODO: Clone any other instances that this clone references.
|
23
|
+
# TODO: Replace clone's references to these new instances.
|
24
|
+
end
|
22
25
|
|
23
|
-
|
24
|
-
|
26
|
+
def action(method, *new_args)
|
27
|
+
@caller_object_clone.send(method, *new_args)
|
28
|
+
end
|
25
29
|
|
26
30
|
end
|
27
|
-
|
28
|
-
def action(method, *new_args)
|
29
|
-
@caller_object_clone.send(method, *new_args)
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
33
31
|
end
|
data/lib/config.rb
CHANGED
@@ -1,45 +1,48 @@
|
|
1
1
|
module Reflekt
|
2
|
-
class Config
|
3
|
-
|
4
|
-
attr_accessor :enabled
|
5
|
-
attr_accessor :reflect_amount
|
6
|
-
attr_accessor :reflect_limit
|
7
|
-
attr_accessor :meta_map
|
8
|
-
attr_accessor :output_path
|
9
|
-
attr_accessor :output_directory
|
10
|
-
|
11
|
-
def initialize()
|
12
|
-
|
13
|
-
# Reflekt is enabled by default and should be disabled on production.
|
14
|
-
@enabled = true
|
15
|
-
|
16
|
-
# The amount of reflections to create per method call.
|
17
|
-
# A control reflection is created in addition to this.
|
18
|
-
@reflect_amount = 5
|
19
|
-
|
20
|
-
# The maximum amount of reflections that can be created per instance/method.
|
21
|
-
# A method called thousands of times doesn't need that many reflections.
|
22
|
-
@reflect_limit = 10
|
23
|
-
|
24
|
-
# The rules that apply to meta types.
|
25
|
-
@meta_map = {
|
26
|
-
:array => [ArrayRule],
|
27
|
-
:bool => [BooleanRule],
|
28
|
-
:int => [IntegerRule],
|
29
|
-
:float => [FloatRule],
|
30
|
-
:null => [NullRule],
|
31
|
-
:object => [ObjectRule],
|
32
|
-
:string => [StringRule]
|
33
|
-
}
|
34
|
-
|
35
|
-
# An absolute path to the directory that contains the output directory.
|
36
|
-
# Defaults to current execution path.
|
37
|
-
@output_path = nil
|
38
|
-
|
39
|
-
# Name of output directory.
|
40
|
-
@output_directory = "reflections"
|
2
|
+
class Config
|
41
3
|
|
42
|
-
|
4
|
+
attr_accessor :enabled
|
5
|
+
attr_accessor :reflect_amount
|
6
|
+
attr_accessor :reflect_limit
|
7
|
+
attr_accessor :meta_map
|
8
|
+
attr_accessor :project_path
|
9
|
+
attr_accessor :output_directory
|
43
10
|
|
44
|
-
|
11
|
+
def initialize()
|
12
|
+
|
13
|
+
# Reflekt is enabled by default and should be disabled on production.
|
14
|
+
@enabled = true
|
15
|
+
|
16
|
+
# Reflekt is untracked in git by default.
|
17
|
+
@git_ignore = true
|
18
|
+
|
19
|
+
# The amount of reflections to create per method call.
|
20
|
+
# A control reflection is created in addition to this.
|
21
|
+
@reflect_amount = 5
|
22
|
+
|
23
|
+
# The maximum amount of reflections that can be created per instance per method.
|
24
|
+
# A method called thousands of times doesn't need that many reflections.
|
25
|
+
@reflect_limit = 10
|
26
|
+
|
27
|
+
# The rules that apply to meta types.
|
28
|
+
@meta_map = {
|
29
|
+
:array => [ArrayRule],
|
30
|
+
:bool => [BooleanRule],
|
31
|
+
:int => [IntegerRule],
|
32
|
+
:float => [FloatRule],
|
33
|
+
:null => [NullRule],
|
34
|
+
:object => [ObjectRule],
|
35
|
+
:string => [StringRule]
|
36
|
+
}
|
37
|
+
|
38
|
+
# An absolute path to the project root directory.
|
39
|
+
# Defaults to current execution path.
|
40
|
+
@project_path = Dir.pwd
|
41
|
+
|
42
|
+
# Name of output directory.
|
43
|
+
@output_directory = "reflections"
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
45
48
|
end
|