reflekt 0.9.3 → 0.9.5
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 +2 -2
- data/lib/Control.rb +2 -2
- data/lib/Reflection.rb +13 -8
- data/lib/{reflekt.rb → Reflekt.rb} +18 -44
- data/lib/Renderer.rb +38 -0
- data/lib/Rule.rb +18 -24
- data/lib/RulePool.rb +44 -0
- data/lib/Ruler.rb +66 -54
- data/lib/rules/FloatRule.rb +24 -0
- data/lib/rules/IntegerRule.rb +27 -0
- data/lib/rules/StringRule.rb +24 -0
- data/lib/web/template.html.erb +1 -1
- metadata +8 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f2048b61fdb7acc0deede9ee5bcae644e6d51fa6e2dab2842f748433ce5ba949
|
4
|
+
data.tar.gz: dce2b1bd92e2eaf90c16e1cad6c27d9b9fc686001c958124f184a5d11a2ebe8d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b4bdebf8083aef0a50806c1970b25f90736dfe68b8373f5a742ef6c7f2e4139e4ca0d273d683d826230069de2039c5fda7428c4ed8147471da00f1e93704f59a
|
7
|
+
data.tar.gz: afbe22e05eb10efe8ead84240c4296546e10570c19e73efea912494e55a85538c8fbed2872c42485ea21ba696a101347e73ec5feee37a568636a154dcae8bcf6
|
data/lib/Accessor.rb
CHANGED
@@ -12,8 +12,8 @@ class Accessor
|
|
12
12
|
|
13
13
|
attr_accessor :setup
|
14
14
|
attr_accessor :db
|
15
|
-
attr_accessor :json
|
16
15
|
attr_accessor :stack
|
16
|
+
attr_accessor :renderer
|
17
17
|
attr_accessor :rules
|
18
18
|
attr_accessor :path
|
19
19
|
attr_accessor :output_path
|
@@ -24,8 +24,8 @@ class Accessor
|
|
24
24
|
|
25
25
|
@setup = nil
|
26
26
|
@db = nil
|
27
|
-
@json = nil
|
28
27
|
@stack = nil
|
28
|
+
@renderer = nil
|
29
29
|
@rules = nil
|
30
30
|
@path = nil
|
31
31
|
@output_path = nil
|
data/lib/Control.rb
CHANGED
@@ -14,11 +14,11 @@ class Control < Reflection
|
|
14
14
|
##
|
15
15
|
def reflect(*args)
|
16
16
|
|
17
|
-
@
|
17
|
+
@inputs = *args
|
18
18
|
|
19
19
|
# Action method with new arguments.
|
20
20
|
begin
|
21
|
-
@output = @clone.send(@method, *@
|
21
|
+
@output = @clone.send(@method, *@inputs)
|
22
22
|
# When fail.
|
23
23
|
rescue StandardError => message
|
24
24
|
@status = FAIL
|
data/lib/Reflection.rb
CHANGED
@@ -57,31 +57,36 @@ class Reflection
|
|
57
57
|
|
58
58
|
# Action method with new arguments.
|
59
59
|
begin
|
60
|
+
|
60
61
|
# Validate input with controls.
|
61
62
|
unless @ruler.nil?
|
62
|
-
if @ruler.validate_inputs(@
|
63
|
+
if @ruler.validate_inputs(@inputs)
|
63
64
|
@status = PASS
|
64
65
|
else
|
65
66
|
@status = FAIL
|
66
67
|
end
|
67
68
|
end
|
69
|
+
|
68
70
|
# Run reflection.
|
69
71
|
@output = @clone.send(@method, *@inputs)
|
70
|
-
|
71
|
-
rescue StandardError => message
|
72
|
-
@status = FAIL
|
73
|
-
@message = message
|
74
|
-
# When pass.
|
75
|
-
else
|
72
|
+
|
76
73
|
# Validate output with controls.
|
77
74
|
unless @ruler.nil?
|
78
|
-
if @ruler.validate_output(@
|
75
|
+
if @ruler.validate_output(@output)
|
79
76
|
@status = PASS
|
80
77
|
else
|
81
78
|
@status = FAIL
|
82
79
|
end
|
83
80
|
return
|
84
81
|
end
|
82
|
+
|
83
|
+
# When fail.
|
84
|
+
rescue StandardError => message
|
85
|
+
@status = FAIL
|
86
|
+
@message = message
|
87
|
+
|
88
|
+
# When no validation and execution fails.
|
89
|
+
else
|
85
90
|
@status = PASS
|
86
91
|
end
|
87
92
|
|
@@ -1,27 +1,27 @@
|
|
1
|
-
require 'set'
|
2
|
-
require 'erb'
|
3
|
-
require 'rowdb'
|
4
|
-
require 'Accessor'
|
5
|
-
require 'Control'
|
6
|
-
require 'Execution'
|
7
|
-
require 'Reflection'
|
8
|
-
require 'Ruler'
|
9
|
-
require 'ShadowStack'
|
10
|
-
|
11
1
|
################################################################################
|
12
|
-
# REFLEKT
|
2
|
+
# REFLEKT - By Maedi Prichard.
|
13
3
|
#
|
14
4
|
# An Execution is created each time a method is called.
|
15
|
-
#
|
16
|
-
#
|
5
|
+
# Many Refections are created per Execution.
|
6
|
+
# Each Reflection executes on a ShadowStack on cloned data.
|
17
7
|
# Then flow is returned to the original method and normal execution continues.
|
18
8
|
#
|
19
9
|
# Usage:
|
20
|
-
#
|
21
10
|
# class ExampleClass
|
22
11
|
# prepend Reflekt
|
23
12
|
################################################################################
|
24
13
|
|
14
|
+
require 'set'
|
15
|
+
require 'erb'
|
16
|
+
require 'rowdb'
|
17
|
+
require 'Accessor'
|
18
|
+
require 'Control'
|
19
|
+
require 'Execution'
|
20
|
+
require 'Reflection'
|
21
|
+
require 'Renderer'
|
22
|
+
require 'Ruler'
|
23
|
+
require 'ShadowStack'
|
24
|
+
|
25
25
|
module Reflekt
|
26
26
|
|
27
27
|
def initialize(*args)
|
@@ -102,7 +102,7 @@ module Reflekt
|
|
102
102
|
@@reflekt.db.write()
|
103
103
|
|
104
104
|
# Render results.
|
105
|
-
|
105
|
+
@@reflekt.renderer.render()
|
106
106
|
|
107
107
|
execution.is_reflecting = false
|
108
108
|
end
|
@@ -121,35 +121,6 @@ module Reflekt
|
|
121
121
|
|
122
122
|
end
|
123
123
|
|
124
|
-
##
|
125
|
-
# Render results.
|
126
|
-
##
|
127
|
-
def reflekt_render()
|
128
|
-
|
129
|
-
# Get JSON.
|
130
|
-
@@reflekt.json = File.read("#{@@reflekt.output_path}/db.json")
|
131
|
-
|
132
|
-
# Save HTML.
|
133
|
-
template = File.read("#{@@reflekt.path}/web/template.html.erb")
|
134
|
-
rendered = ERB.new(template).result(binding)
|
135
|
-
File.open("#{@@reflekt.output_path}/index.html", 'w+') do |f|
|
136
|
-
f.write rendered
|
137
|
-
end
|
138
|
-
|
139
|
-
# Add JS.
|
140
|
-
javascript = File.read("#{@@reflekt.path}/web/script.js")
|
141
|
-
File.open("#{@@reflekt.output_path}/script.js", 'w+') do |f|
|
142
|
-
f.write javascript
|
143
|
-
end
|
144
|
-
|
145
|
-
# Add CSS.
|
146
|
-
stylesheet = File.read("#{@@reflekt.path}/web/style.css")
|
147
|
-
File.open("#{@@reflekt.output_path}/style.css", 'w+') do |f|
|
148
|
-
f.write stylesheet
|
149
|
-
end
|
150
|
-
|
151
|
-
end
|
152
|
-
|
153
124
|
private
|
154
125
|
|
155
126
|
def self.prepended(base)
|
@@ -219,6 +190,9 @@ module Reflekt
|
|
219
190
|
# A method called thousands of times doesn't need that many reflections.
|
220
191
|
@@reflekt.reflection_limit = 10
|
221
192
|
|
193
|
+
# Create renderer.
|
194
|
+
@@reflekt.renderer = Renderer.new(@@reflekt.path, @@reflekt.output_path)
|
195
|
+
|
222
196
|
return true
|
223
197
|
end
|
224
198
|
|
data/lib/Renderer.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
class Renderer
|
2
|
+
|
3
|
+
def initialize(path, output_path)
|
4
|
+
@path = path
|
5
|
+
@output_path = output_path
|
6
|
+
end
|
7
|
+
|
8
|
+
##
|
9
|
+
# Render results.
|
10
|
+
##
|
11
|
+
def render()
|
12
|
+
|
13
|
+
# Get JSON.
|
14
|
+
json = File.read("#{@output_path}/db.json")
|
15
|
+
|
16
|
+
# Save HTML.
|
17
|
+
template = File.read("#{@path}/web/template.html.erb")
|
18
|
+
rendered = ERB.new(template).result(binding)
|
19
|
+
File.open("#{@output_path}/index.html", 'w+') do |f|
|
20
|
+
f.write rendered
|
21
|
+
end
|
22
|
+
|
23
|
+
# Add JS.
|
24
|
+
javascript = File.read("#{@path}/web/script.js")
|
25
|
+
File.open("#{@output_path}/script.js", 'w+') do |f|
|
26
|
+
f.write javascript
|
27
|
+
end
|
28
|
+
|
29
|
+
# Add CSS.
|
30
|
+
stylesheet = File.read("#{@path}/web/style.css")
|
31
|
+
File.open("#{@output_path}/style.css", 'w+') do |f|
|
32
|
+
f.write stylesheet
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
end
|
data/lib/Rule.rb
CHANGED
@@ -1,38 +1,32 @@
|
|
1
|
+
################################################################################
|
2
|
+
# RULES
|
3
|
+
#
|
4
|
+
# Abstract class.
|
5
|
+
# See lib/rules for rules.
|
6
|
+
################################################################################
|
7
|
+
|
1
8
|
require 'set'
|
2
9
|
|
3
10
|
class Rule
|
4
11
|
|
5
|
-
|
6
|
-
attr_accessor :min
|
7
|
-
attr_accessor :max
|
8
|
-
attr_accessor :length
|
9
|
-
attr_accessor :types
|
10
|
-
attr_accessor :values
|
11
|
-
|
12
|
+
# Each rule intitalises itself.
|
12
13
|
def initialize()
|
13
|
-
|
14
|
-
@types = Set.new
|
15
|
-
@values = Set.new
|
16
|
-
@min = nil
|
17
|
-
@max = nil
|
18
|
-
@length = nil
|
19
|
-
|
14
|
+
@values = nil
|
20
15
|
end
|
21
16
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
##
|
26
|
-
def add_type(type)
|
27
|
-
@types.add(type)
|
17
|
+
# Each rule loads up an array of values.
|
18
|
+
def load(value)
|
19
|
+
@values << value
|
28
20
|
end
|
29
21
|
|
30
|
-
|
31
|
-
|
22
|
+
# Each rule trains on values to determine its patterns.
|
23
|
+
def train()
|
24
|
+
|
32
25
|
end
|
33
26
|
|
34
|
-
|
35
|
-
|
27
|
+
# Each rule compares the data it has with the data it's given.
|
28
|
+
def validate()
|
29
|
+
|
36
30
|
end
|
37
31
|
|
38
32
|
end
|
data/lib/RulePool.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
################################################################################
|
2
|
+
# RULE POOL
|
3
|
+
#
|
4
|
+
# A collection of rules generated for an argument.
|
5
|
+
# Duplicates will not be added to the sets.
|
6
|
+
################################################################################
|
7
|
+
|
8
|
+
require 'set'
|
9
|
+
require 'Rule'
|
10
|
+
|
11
|
+
class RulePool
|
12
|
+
|
13
|
+
attr_accessor :types
|
14
|
+
attr_accessor :rules
|
15
|
+
|
16
|
+
def initialize()
|
17
|
+
|
18
|
+
@types = Set.new
|
19
|
+
@rules = {}
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
def train()
|
24
|
+
|
25
|
+
rules.each do |rule|
|
26
|
+
rule.train()
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
def validate(value)
|
32
|
+
result = true
|
33
|
+
|
34
|
+
rules.each do |rule|
|
35
|
+
result = rule.validate(value)
|
36
|
+
if result == false
|
37
|
+
result = false
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
return result
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
data/lib/Ruler.rb
CHANGED
@@ -1,4 +1,10 @@
|
|
1
|
-
|
1
|
+
################################################################################
|
2
|
+
# RULER
|
3
|
+
#
|
4
|
+
# Aggregate a method's inputs and output into a series of generic rules.
|
5
|
+
################################################################################
|
6
|
+
|
7
|
+
require 'RulePool'
|
2
8
|
|
3
9
|
class Ruler
|
4
10
|
|
@@ -9,9 +15,9 @@ class Ruler
|
|
9
15
|
|
10
16
|
def initialize()
|
11
17
|
|
18
|
+
# Reflections.
|
12
19
|
@controls = nil
|
13
|
-
|
14
|
-
# Rules.
|
20
|
+
# Arguments.
|
15
21
|
@inputs = []
|
16
22
|
@output = nil
|
17
23
|
|
@@ -22,90 +28,96 @@ class Ruler
|
|
22
28
|
@controls = controls
|
23
29
|
@controls.each_with_index do |control, index|
|
24
30
|
|
25
|
-
#
|
31
|
+
# Create rules for each input.
|
26
32
|
control[INPUT].each_with_index do |input, index|
|
27
33
|
unless input.nil?
|
28
|
-
|
29
|
-
# Create rule.
|
30
|
-
if @inputs[index].nil?
|
31
|
-
rule = Rule.new()
|
32
|
-
@inputs[index] = rule
|
33
|
-
else
|
34
|
-
rule = @inputs[index]
|
35
|
-
end
|
36
|
-
|
37
|
-
# Add rules to rule.
|
38
|
-
unless input[TYPE].nil? || input[TYPE].empty?
|
39
|
-
rule.add_type(input[TYPE].class)
|
40
|
-
end
|
41
|
-
unless input[VALUE].nil? || input[VALUE].empty?
|
42
|
-
rule.add_value(input[VALUE])
|
43
|
-
end
|
44
|
-
|
45
|
-
index = index + 1
|
34
|
+
@inputs[index] = load_rule_pool(@inputs[index], input[TYPE], input[VALUE])
|
46
35
|
end
|
47
36
|
end
|
48
37
|
|
49
|
-
#
|
38
|
+
# Create rules for the output.
|
50
39
|
output = control[OUTPUT]
|
51
40
|
unless control[OUTPUT].nil?
|
41
|
+
@output = load_rule_pool(@output, output[TYPE], output[VALUE])
|
42
|
+
end
|
52
43
|
|
53
|
-
|
54
|
-
if @output.nil?
|
55
|
-
rule = Rule.new()
|
56
|
-
@output = rule
|
57
|
-
else
|
58
|
-
rule = @output
|
59
|
-
end
|
44
|
+
end
|
60
45
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
46
|
+
end
|
47
|
+
|
48
|
+
def load_rule_pool(rule_pool, type, value)
|
49
|
+
|
50
|
+
if rule_pool.nil?
|
51
|
+
rule_pool = RulePool.new()
|
52
|
+
end
|
53
|
+
|
54
|
+
# Track data type.
|
55
|
+
rule_pool.types << type
|
56
|
+
|
57
|
+
# Get rule for this data type.
|
58
|
+
rule = nil
|
68
59
|
|
60
|
+
case type
|
61
|
+
when "Integer"
|
62
|
+
unless rule_pool.rules.key? IntegerRule
|
63
|
+
rule = IntegerRule.new()
|
64
|
+
rule_pool.rules << rule
|
65
|
+
else
|
66
|
+
rule = rule_pool.rules[IntegerRule]
|
69
67
|
end
|
68
|
+
when "String"
|
69
|
+
unless rule_pool.rules.key? StringRule
|
70
|
+
rule = StringRule.new()
|
71
|
+
rule_pool.rules << rule
|
72
|
+
else
|
73
|
+
rule = rule_pool.rules[IntegerRule]
|
74
|
+
end
|
75
|
+
end
|
70
76
|
|
77
|
+
# Add value to rule.
|
78
|
+
unless rule.nil?
|
79
|
+
rule.load(value)
|
71
80
|
end
|
72
81
|
|
82
|
+
return rule_pool
|
83
|
+
|
73
84
|
end
|
74
85
|
|
75
86
|
def train()
|
76
87
|
|
77
|
-
@inputs.each do |
|
78
|
-
|
79
|
-
|
80
|
-
numbers = rule.values.select {|num| num.class == Integer }
|
81
|
-
numbers.sort!
|
82
|
-
rule.min = numbers.first
|
83
|
-
rule.max = numbers.last
|
88
|
+
@inputs.each do |rule_pool|
|
89
|
+
unless rule_pool.nil?
|
90
|
+
rule_pool.train()
|
84
91
|
end
|
92
|
+
end
|
85
93
|
|
94
|
+
unless @output.nil?
|
95
|
+
@output.train()
|
86
96
|
end
|
87
97
|
|
88
98
|
end
|
89
99
|
|
90
|
-
def validate_inputs(
|
100
|
+
def validate_inputs(inputs)
|
91
101
|
result = true
|
102
|
+
|
92
103
|
inputs.each_with_index do |value, index|
|
93
|
-
|
94
|
-
|
95
|
-
result = false
|
96
|
-
result = false if value > rule.max
|
104
|
+
rule_pool = @inputs[index]
|
105
|
+
unless rule_pool.validate(input)
|
106
|
+
result = false
|
97
107
|
end
|
98
108
|
end
|
109
|
+
|
99
110
|
return result
|
100
111
|
end
|
101
112
|
|
102
|
-
def validate_output(
|
113
|
+
def validate_output(output)
|
103
114
|
result = true
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
result = false
|
115
|
+
|
116
|
+
rule_pool = @output
|
117
|
+
unless rule_pool.validate(output)
|
118
|
+
result = false
|
108
119
|
end
|
120
|
+
|
109
121
|
return result
|
110
122
|
end
|
111
123
|
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class FloatRule < Rule
|
2
|
+
|
3
|
+
attr_accessor :min
|
4
|
+
attr_accessor :max
|
5
|
+
|
6
|
+
def initialize()
|
7
|
+
@min = nil
|
8
|
+
@max = nil
|
9
|
+
end
|
10
|
+
|
11
|
+
def load(value)
|
12
|
+
@values << value
|
13
|
+
end
|
14
|
+
|
15
|
+
def train()
|
16
|
+
# TODO.
|
17
|
+
end
|
18
|
+
|
19
|
+
def validate()
|
20
|
+
# TODO.
|
21
|
+
true
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class IntegerRule < Rule
|
2
|
+
|
3
|
+
attr_accessor :min
|
4
|
+
attr_accessor :max
|
5
|
+
|
6
|
+
def initialize()
|
7
|
+
@min = nil
|
8
|
+
@max = nil
|
9
|
+
end
|
10
|
+
|
11
|
+
def load(value)
|
12
|
+
@values << value
|
13
|
+
end
|
14
|
+
|
15
|
+
def train()
|
16
|
+
numbers = @values.select {|num| num.class == Integer }
|
17
|
+
numbers.sort!
|
18
|
+
@min = numbers.first
|
19
|
+
@max = numbers.last
|
20
|
+
end
|
21
|
+
|
22
|
+
def validate()
|
23
|
+
return false if value < rule.min
|
24
|
+
return false if value > rule.max
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class StringRule < Rule
|
2
|
+
|
3
|
+
attr_accessor :min_length
|
4
|
+
attr_accessor :max_length
|
5
|
+
|
6
|
+
def initialize()
|
7
|
+
@min_length = nil
|
8
|
+
@max_length = nil
|
9
|
+
end
|
10
|
+
|
11
|
+
def load(value)
|
12
|
+
@values << value
|
13
|
+
end
|
14
|
+
|
15
|
+
def train()
|
16
|
+
# TODO.
|
17
|
+
end
|
18
|
+
|
19
|
+
def validate()
|
20
|
+
# TODO.
|
21
|
+
true
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
data/lib/web/template.html.erb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reflekt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Maedi Prichard
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-10-
|
11
|
+
date: 2020-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rowdb
|
@@ -34,10 +34,15 @@ files:
|
|
34
34
|
- lib/Control.rb
|
35
35
|
- lib/Execution.rb
|
36
36
|
- lib/Reflection.rb
|
37
|
+
- lib/Reflekt.rb
|
38
|
+
- lib/Renderer.rb
|
37
39
|
- lib/Rule.rb
|
40
|
+
- lib/RulePool.rb
|
38
41
|
- lib/Ruler.rb
|
39
42
|
- lib/ShadowStack.rb
|
40
|
-
- lib/
|
43
|
+
- lib/rules/FloatRule.rb
|
44
|
+
- lib/rules/IntegerRule.rb
|
45
|
+
- lib/rules/StringRule.rb
|
41
46
|
- lib/web/script.js
|
42
47
|
- lib/web/style.css
|
43
48
|
- lib/web/template.html.erb
|