reflekt 0.5.0 → 0.7.0
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/reflekt.rb +51 -31
- data/lib/web/style.css +76 -0
- data/lib/web/template.html.erb +51 -16
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d9282a0295c04e95cec339bfa6563a517ac12d964f6310320056669ad52b86e1
|
|
4
|
+
data.tar.gz: 8ad30ad01a3c021d60eb645e56ddf7aea528860ca30588bb9269dac0a5cc74d8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e7be8cc94f17f83c4c5131862c0ffa424c7976f4baae38d535e2a45f77318d47543493b0259dc0a7a62ad7481a380615c09030060d29ef0462c4ab6bfa6d5cb2
|
|
7
|
+
data.tar.gz: 7fcee25ce29344e2181a8db3f3020c11ab4668560651869e81cfa5e059aa31ae35ce45c06892a19946b8509f2d592e0dc7d171ede27b1d6b5f45fa1dbff3744c
|
data/lib/reflekt.rb
CHANGED
|
@@ -20,37 +20,53 @@ module Reflekt
|
|
|
20
20
|
@reflekt_forked = false
|
|
21
21
|
@reflekt_clones = []
|
|
22
22
|
|
|
23
|
+
# Limit the amount of clones that can be created per instance.
|
|
24
|
+
# A method called 30,000 times doesn't need that many reflections.
|
|
25
|
+
@reflekt_limit = 5
|
|
26
|
+
@reflekt_count = 0
|
|
27
|
+
|
|
23
28
|
# Override methods.
|
|
24
29
|
self.class.instance_methods(false).each do |method|
|
|
25
30
|
self.define_singleton_method(method) do |*args|
|
|
26
31
|
|
|
27
32
|
# When method called in flow.
|
|
28
33
|
if @reflekt_forked
|
|
29
|
-
unless self.class.deflekted?(method)
|
|
30
|
-
|
|
31
|
-
# Reflekt on method.
|
|
32
|
-
@reflekt_clones.each do |clone|
|
|
33
|
-
reflekt_action(clone, method, *args)
|
|
34
|
-
end
|
|
35
34
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
35
|
+
if @reflekt_count < @reflekt_limit
|
|
36
|
+
unless self.class.deflekted?(method)
|
|
37
|
+
|
|
38
|
+
# Reflekt on method.
|
|
39
|
+
@reflekt_clones.each do |clone|
|
|
40
|
+
reflekt_action(clone, method, *args)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Save results.
|
|
44
|
+
@@reflekt_db.write()
|
|
45
|
+
|
|
46
|
+
# Render results.
|
|
47
|
+
@@reflekt_json = File.read("#{@@reflekt_output_path}/db.json")
|
|
48
|
+
template = File.read("#{@@reflekt_path}/web/template.html.erb")
|
|
49
|
+
rendered = ERB.new(template).result(binding)
|
|
50
|
+
File.open("#{@@reflekt_output_path}/index.html", 'w+') do |f|
|
|
51
|
+
f.write rendered
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Add JS.
|
|
55
|
+
alpinejs = File.read("#{@@reflekt_path}/web/alpine.js")
|
|
56
|
+
File.open("#{@@reflekt_output_path}/alpine.js", 'w+') do |f|
|
|
57
|
+
f.write alpinejs
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# Add CSS.
|
|
61
|
+
stylesheet = File.read("#{@@reflekt_path}/web/style.css")
|
|
62
|
+
File.open("#{@@reflekt_output_path}/style.css", 'w+') do |f|
|
|
63
|
+
f.write stylesheet
|
|
64
|
+
end
|
|
46
65
|
|
|
47
|
-
# Add libraries.
|
|
48
|
-
alpinejs = File.read("#{@@reflekt_path}/web/alpine.js")
|
|
49
|
-
File.open("#{@@reflekt_output_path}/alpine.js", 'w+') do |f|
|
|
50
|
-
f.write alpinejs
|
|
51
66
|
end
|
|
52
|
-
|
|
67
|
+
@reflekt_count = @reflekt_count + 1
|
|
53
68
|
end
|
|
69
|
+
|
|
54
70
|
end
|
|
55
71
|
|
|
56
72
|
# Continue method flow.
|
|
@@ -82,7 +98,7 @@ module Reflekt
|
|
|
82
98
|
class_name = clone.class.to_s
|
|
83
99
|
method_name = method.to_s
|
|
84
100
|
|
|
85
|
-
# Create new arguments.
|
|
101
|
+
# Create new arguments that are deviations on inputted type.
|
|
86
102
|
new_args = []
|
|
87
103
|
args.each do |arg|
|
|
88
104
|
case arg
|
|
@@ -101,13 +117,13 @@ module Reflekt
|
|
|
101
117
|
reflection = {
|
|
102
118
|
"time" => Time.now.to_i,
|
|
103
119
|
}
|
|
104
|
-
# When
|
|
120
|
+
# When fail.
|
|
105
121
|
rescue StandardError => error
|
|
106
122
|
reflection["status"] = "error"
|
|
107
123
|
reflection["error"] = error
|
|
108
|
-
# When
|
|
124
|
+
# When pass.
|
|
109
125
|
else
|
|
110
|
-
reflection["status"] = "
|
|
126
|
+
reflection["status"] = "pass"
|
|
111
127
|
end
|
|
112
128
|
|
|
113
129
|
# Save reflection.
|
|
@@ -118,15 +134,15 @@ module Reflekt
|
|
|
118
134
|
|
|
119
135
|
private
|
|
120
136
|
|
|
121
|
-
# Prepend Klass to the instance's singleton class.
|
|
122
137
|
def self.prepended(base)
|
|
123
|
-
|
|
138
|
+
# Prepend class methods to the instance's singleton class.
|
|
139
|
+
base.singleton_class.prepend(SingletonClassMethods)
|
|
124
140
|
|
|
125
|
-
@@reflekt_setup ||=
|
|
141
|
+
@@reflekt_setup ||= reflekt_setup_class
|
|
126
142
|
end
|
|
127
143
|
|
|
128
|
-
# Setup
|
|
129
|
-
def self.
|
|
144
|
+
# Setup class.
|
|
145
|
+
def self.reflekt_setup_class()
|
|
130
146
|
|
|
131
147
|
# Receive configuration from host application.
|
|
132
148
|
$ENV ||= {}
|
|
@@ -153,7 +169,7 @@ module Reflekt
|
|
|
153
169
|
return true
|
|
154
170
|
end
|
|
155
171
|
|
|
156
|
-
module
|
|
172
|
+
module SingletonClassMethods
|
|
157
173
|
|
|
158
174
|
@@deflekted_methods = Set.new
|
|
159
175
|
|
|
@@ -171,6 +187,10 @@ module Reflekt
|
|
|
171
187
|
false
|
|
172
188
|
end
|
|
173
189
|
|
|
190
|
+
def reflekt_limit(amount)
|
|
191
|
+
@reflekt_limit = amount
|
|
192
|
+
end
|
|
193
|
+
|
|
174
194
|
end
|
|
175
195
|
|
|
176
196
|
end
|
data/lib/web/style.css
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
body {
|
|
2
|
+
padding: 0.5rem;
|
|
3
|
+
background: #C9D2E6;
|
|
4
|
+
font-family: 'Roboto', sans-serif;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.container {
|
|
8
|
+
margin: 0 auto;
|
|
9
|
+
max-width: 800px;
|
|
10
|
+
padding: 2rem;
|
|
11
|
+
background: white;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
#header {
|
|
15
|
+
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
#logo {
|
|
19
|
+
display: block;
|
|
20
|
+
margin: 0 auto;
|
|
21
|
+
max-width: 100px;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
ul.panels,
|
|
25
|
+
ul.reflections {
|
|
26
|
+
padding-left: 0;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
li.panel {
|
|
30
|
+
list-style: none;
|
|
31
|
+
padding: 1rem;
|
|
32
|
+
border: 5px solid #dadcdc;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/* Reflection. */
|
|
36
|
+
.reflection {
|
|
37
|
+
display: flex;
|
|
38
|
+
align-items: center;
|
|
39
|
+
flex-direction: row;
|
|
40
|
+
color: white;
|
|
41
|
+
background: #A9B6D2;
|
|
42
|
+
}
|
|
43
|
+
.reflection.class {
|
|
44
|
+
padding: 2rem;
|
|
45
|
+
margin-bottom: 1rem;
|
|
46
|
+
}
|
|
47
|
+
.reflection.class h2 {
|
|
48
|
+
margin: 0;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.reflection.method {
|
|
52
|
+
padding: 2rem;
|
|
53
|
+
margin-left: 1rem;
|
|
54
|
+
margin-bottom: 1rem;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/* Stats. */
|
|
58
|
+
.stats {
|
|
59
|
+
margin-left: auto;
|
|
60
|
+
}
|
|
61
|
+
.stat {
|
|
62
|
+
color: #efefef;
|
|
63
|
+
font-size: 3.5rem;
|
|
64
|
+
font-family: 'Merriweather', serif;
|
|
65
|
+
}
|
|
66
|
+
.method .stat {
|
|
67
|
+
font-size: 2.5rem;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/* State. */
|
|
71
|
+
.reflection.pass {
|
|
72
|
+
background: #008C32;
|
|
73
|
+
}
|
|
74
|
+
.reflection.fail {
|
|
75
|
+
background: #D04700;
|
|
76
|
+
}
|
data/lib/web/template.html.erb
CHANGED
|
@@ -6,8 +6,10 @@
|
|
|
6
6
|
<meta name="description" content="">
|
|
7
7
|
<meta name="author" content="">
|
|
8
8
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
9
|
-
<link rel="stylesheet" href="">
|
|
9
|
+
<link rel="stylesheet" href="style.css">
|
|
10
10
|
<link rel="shortcut icon" href="">
|
|
11
|
+
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;700&display=swap" rel="stylesheet">
|
|
12
|
+
<link href="https://fonts.googleapis.com/css2?family=Merriweather&display=swap" rel="stylesheet">
|
|
11
13
|
</head>
|
|
12
14
|
<body>
|
|
13
15
|
|
|
@@ -16,6 +18,7 @@
|
|
|
16
18
|
function getReflections() {
|
|
17
19
|
|
|
18
20
|
var reflections = JSON.parse(<%= @@reflekt_json %>);
|
|
21
|
+
console.log(reflections);
|
|
19
22
|
var results = {};
|
|
20
23
|
|
|
21
24
|
if ('reflekt' in reflections) {
|
|
@@ -44,23 +47,37 @@
|
|
|
44
47
|
return obj;
|
|
45
48
|
}, {});
|
|
46
49
|
|
|
50
|
+
var pass_rate = (pass_count['pass'] / method.length) * 100;
|
|
47
51
|
results[class_id]['methods'][method_id] = {
|
|
48
52
|
'stats': {
|
|
49
|
-
'pass_rate':
|
|
53
|
+
'pass_rate': pass_rate,
|
|
50
54
|
'test_count': method.length,
|
|
51
|
-
'pass_count': pass_count['
|
|
55
|
+
'pass_count': pass_count['pass']
|
|
52
56
|
}
|
|
53
57
|
};
|
|
58
|
+
if (pass_rate == 100) {
|
|
59
|
+
results[class_id]['methods'][method_id]['status'] = 'pass';
|
|
60
|
+
}
|
|
61
|
+
else if (pass_rate < 100) {
|
|
62
|
+
results[class_id]['methods'][method_id]['status'] = 'fail';
|
|
63
|
+
}
|
|
54
64
|
|
|
55
65
|
// Class pass rate.
|
|
56
66
|
results[class_id]['stats']['test_count'] += method.length;
|
|
57
|
-
results[class_id]['stats']['pass_count'] += pass_count['
|
|
67
|
+
results[class_id]['stats']['pass_count'] += pass_count['pass'];
|
|
58
68
|
|
|
59
69
|
}
|
|
60
70
|
|
|
61
71
|
// Class pass rate.
|
|
62
72
|
var class_stats = results[class_id]['stats'];
|
|
63
|
-
|
|
73
|
+
var pass_rate = (class_stats['pass_count'] / class_stats['test_count']) * 100;
|
|
74
|
+
class_stats['pass_rate'] = pass_rate;
|
|
75
|
+
if (pass_rate == 100) {
|
|
76
|
+
results[class_id]['status'] = 'pass';
|
|
77
|
+
}
|
|
78
|
+
else if (pass_rate < 100) {
|
|
79
|
+
results[class_id]['status'] = 'fail';
|
|
80
|
+
}
|
|
64
81
|
}
|
|
65
82
|
|
|
66
83
|
return { refs: results };
|
|
@@ -68,23 +85,41 @@
|
|
|
68
85
|
|
|
69
86
|
</script>
|
|
70
87
|
|
|
71
|
-
<div x-data="getReflections()">
|
|
88
|
+
<div class="container" x-data="getReflections()">
|
|
72
89
|
|
|
73
|
-
<
|
|
90
|
+
<div id="header">
|
|
91
|
+
<svg id="logo" enable-background="new 0 0 500 500" viewBox="0 0 500 500" xmlns="http://www.w3.org/2000/svg">
|
|
92
|
+
<path d="m307.5 80.5h-115l-57.5 205h230z" fill="#0047d0"/>
|
|
93
|
+
<path d="m178 76.5-53.1-44-117.9 139 116 112z" fill="#d04800"/>
|
|
94
|
+
<path d="m190.4 467.5h115l57.5-168h-229z" fill="#0047d0" opacity=".7"/>
|
|
95
|
+
<path d="m177 467.5-81-85-92-197 115 113z" fill="#d04800" opacity=".7"/>
|
|
96
|
+
<g fill="#008c33"><path d="m322 76.5 53.1-44 118 139-116 112z"/><path d="m320 467.5 84-85 92-197-117 113z" opacity=".7"/></g>
|
|
97
|
+
</svg>
|
|
98
|
+
</div>
|
|
74
99
|
|
|
100
|
+
<ul class="panels">
|
|
75
101
|
<template x-for="[class_id, klass] in Object.entries(getReflections()['refs'])" :key="class_id">
|
|
76
|
-
<li>
|
|
77
|
-
<div x-text="class_id"></div>
|
|
78
|
-
<div x-text="klass.stats.pass_rate"></div>
|
|
79
102
|
|
|
80
|
-
|
|
103
|
+
<li class="panel">
|
|
104
|
+
|
|
105
|
+
<div class="reflection class" x-bind:class="` ${ klass.status } `">
|
|
106
|
+
<h2 x-text="` ${class_id}() `"></h2>
|
|
107
|
+
<div class="stats">
|
|
108
|
+
<div class="stat" x-text="` ${klass.stats.pass_rate}% `"></div>
|
|
109
|
+
</div>
|
|
110
|
+
</div>
|
|
111
|
+
|
|
112
|
+
<ul class="reflections methods">
|
|
81
113
|
<template x-for="[method_id, method] in Object.entries(klass['methods'])" :key="method_id">
|
|
82
|
-
<
|
|
83
|
-
<
|
|
84
|
-
<div
|
|
85
|
-
|
|
114
|
+
<li class="reflection method" x-bind:class="` ${ method.status } `">
|
|
115
|
+
<h3 x-text="` ${method_id}() `"></h3>
|
|
116
|
+
<div class="stats">
|
|
117
|
+
<div class="stat" x-text="` ${method.stats.pass_rate}% `"></div>
|
|
118
|
+
</div>
|
|
119
|
+
</li>
|
|
86
120
|
</template>
|
|
87
|
-
</
|
|
121
|
+
</ul>
|
|
122
|
+
|
|
88
123
|
</li>
|
|
89
124
|
</template>
|
|
90
125
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: reflekt
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.7.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Maedi Prichard
|
|
@@ -32,6 +32,7 @@ extra_rdoc_files: []
|
|
|
32
32
|
files:
|
|
33
33
|
- lib/reflekt.rb
|
|
34
34
|
- lib/web/alpine.js
|
|
35
|
+
- lib/web/style.css
|
|
35
36
|
- lib/web/template.html.erb
|
|
36
37
|
homepage: https://github.com/maedi/reflekt
|
|
37
38
|
licenses:
|