reflekt 0.7.1 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4a8f70f5646d8276359aaf74b703172bbadc1d9025d8a716183578365fd91014
4
- data.tar.gz: 9666d1aadc1b8ef280ac68da0c66f75b5c399d4eb67898079abcb82aa23baf23
3
+ metadata.gz: d92d12a27556a25c258f83cf2983ffc2758a70c5cd359f4e7beafb862e88e68c
4
+ data.tar.gz: be5fa824eb0e6cd3bd15e03da504c40a65e471687881a5fbfcebc0d0906399fd
5
5
  SHA512:
6
- metadata.gz: 68cecdc1e2552bc59dc4fb3a5001f094425a78dd9b96504e2f3270a9cf82b6767e719e8398731d57c58a6ddf20ca30fe3cae66ff75a172bf7d9f73ce758c7b3b
7
- data.tar.gz: cfabac18abb5dda7b90d3cfa0e8494ece8f9c2a48f3fc8a5c8fff8162eddfbee9b8bc9210fd05ae79d384ded033ef69a6eb1b57d84675dd9c0a71e1ab3dbaf67
6
+ metadata.gz: 9ffb39bc278932fd985731c7e509767e79c3356da41d7114a57cfe47a774bb97742ae283837859e2ff158ff84121e2b565c2bf25aff1ae0e8345671b9bd8da22
7
+ data.tar.gz: 3db51deab75140780e718e3536ab06696a1d0ef5308b1cbfcf2fb8a56dc9144905f22f2f53e918afcd7d1e962416134fc41a07676e17c4a16b935c70aece19fb
@@ -13,10 +13,18 @@ require 'rowdb'
13
13
 
14
14
  module Reflekt
15
15
 
16
- REFLEKT_STATUS = "s"
17
- REFLEKT_PASS = "p"
18
- REFLEKT_FAIL = "f"
16
+ # Reflection keys.
17
+ REFLEKT_TIME = "t"
18
+ REFLEKT_INPUT = "i"
19
+ REFLEKT_OUTPUT = "o"
20
+ REFLEKT_TYPE = "T"
21
+ REFLEKT_COUNT = "C"
22
+ REFLEKT_VALUE = "V"
23
+ REFLEKT_STATUS = "s"
19
24
  REFLEKT_MESSAGE = "m"
25
+ # Reflection values.
26
+ REFLEKT_PASS = "p"
27
+ REFLEKT_FAIL = "f"
20
28
 
21
29
  @@reflekt_clone_count = 5
22
30
 
@@ -85,23 +93,30 @@ module Reflekt
85
93
  class_name = clone.class.to_s
86
94
  method_name = method.to_s
87
95
 
96
+ # TODO: Create control fork. Get good value. Check against it.
97
+
88
98
  # Create new arguments that are deviations on inputted type.
89
- new_args = []
99
+ input = []
100
+
90
101
  args.each do |arg|
91
102
  case arg
92
103
  when Integer
93
- new_args << rand(9999)
104
+ input << rand(9999)
94
105
  else
95
- new_args << arg
106
+ input << arg
96
107
  end
97
108
  end
98
109
 
99
110
  # Action method with new arguments.
100
111
  begin
101
- clone.send(method, *new_args)
112
+ output = clone.send(method, *input)
102
113
 
103
114
  # Build reflection.
104
- reflection = { "time" => Time.now.to_i }
115
+ reflection = {
116
+ REFLEKT_TIME => Time.now.to_i,
117
+ REFLEKT_INPUT => reflekt_normalize_input(input),
118
+ REFLEKT_OUTPUT => reflekt_normalize_output(output)
119
+ }
105
120
 
106
121
  # When fail.
107
122
  rescue StandardError => message
@@ -117,6 +132,63 @@ module Reflekt
117
132
 
118
133
  end
119
134
 
135
+ ##
136
+ # Normalize inputs.
137
+ #
138
+ # @param args - The actual inputs.
139
+ # @return - A generic inputs representation.
140
+ ##
141
+ def reflekt_normalize_input(args)
142
+ inputs = []
143
+ args.each do |arg|
144
+ input = {
145
+ REFLEKT_TYPE => arg.class.to_s,
146
+ REFLEKT_VALUE => reflekt_normalize_value(arg)
147
+ }
148
+ if (arg.class == Array)
149
+ input[REFLEKT_COUNT] = arg.count
150
+ end
151
+ inputs << input
152
+ end
153
+ inputs
154
+ end
155
+
156
+ ##
157
+ # Normalize output.
158
+ #
159
+ # @param output - The actual output.
160
+ # @return - A generic output representation.
161
+ ##
162
+ def reflekt_normalize_output(output)
163
+
164
+ o = {
165
+ REFLEKT_TYPE => output.class.to_s,
166
+ REFLEKT_VALUE => reflekt_normalize_value(output)
167
+ }
168
+
169
+ if (output.class == Array || output.class == Hash)
170
+ o[REFLEKT_COUNT] = output.count
171
+ elsif (output.class == TrueClass || output.class == FalseClass)
172
+ o[REFLEKT_TYPE] = :Boolean
173
+ end
174
+
175
+ return o
176
+
177
+ end
178
+
179
+ def reflekt_normalize_value(value)
180
+
181
+ unless value.nil?
182
+ value = value.to_s.gsub(/\r?\n/, " ").to_s
183
+ if value.length >= 30
184
+ value = value[0, value.rindex(/\s/,30)].rstrip() + '...'
185
+ end
186
+ end
187
+
188
+ return value
189
+
190
+ end
191
+
120
192
  def reflekt_render()
121
193
 
122
194
  # Render results.
@@ -128,8 +200,8 @@ module Reflekt
128
200
  end
129
201
 
130
202
  # Add JS.
131
- javascript = File.read("#{@@reflekt_path}/web/alpine.js")
132
- File.open("#{@@reflekt_output_path}/alpine.js", 'w+') do |f|
203
+ javascript = File.read("#{@@reflekt_path}/web/script.js")
204
+ File.open("#{@@reflekt_output_path}/script.js", 'w+') do |f|
133
205
  f.write javascript
134
206
  end
135
207
 
@@ -185,7 +257,7 @@ module Reflekt
185
257
  ##
186
258
  # Skip a method.
187
259
  #
188
- # method - A symbol representing the method name.
260
+ # @param method - A symbol representing the method name.
189
261
  ##
190
262
  def reflekt_skip(method)
191
263
  @@deflekted_methods.add(method)
File without changes
@@ -1,3 +1,4 @@
1
+ /* Layout. */
1
2
  body {
2
3
  padding: 0.5rem;
3
4
  background: #C9D2E6;
@@ -6,52 +7,46 @@ body {
6
7
 
7
8
  .container {
8
9
  margin: 0 auto;
9
- max-width: 800px;
10
+ max-width: 1000px;
10
11
  padding: 2rem;
11
12
  background: white;
12
13
  }
13
14
 
14
- #header {
15
-
16
- }
17
-
15
+ /* Header. */
18
16
  #logo {
19
17
  display: block;
20
18
  margin: 0 auto;
21
19
  max-width: 100px;
22
20
  }
23
21
 
24
- ul.panels,
22
+ /* Structure */
23
+ ul.classes,
24
+ ul.methods,
25
25
  ul.reflections {
26
26
  padding-left: 0;
27
27
  }
28
28
 
29
- li.panel {
29
+ li.class-container,
30
+ li.method-container {
30
31
  list-style: none;
31
32
  padding: 1rem;
32
33
  border: 5px solid #dadcdc;
33
34
  }
34
35
 
35
- /* Reflection. */
36
- .reflection {
36
+ /* State. */
37
+ .status-row {
38
+ width: 100%;
37
39
  display: flex;
38
40
  align-items: center;
39
41
  flex-direction: row;
40
42
  color: white;
41
43
  background: #A9B6D2;
42
44
  }
43
- .reflection.class {
44
- padding: 2rem;
45
- margin-bottom: 1rem;
46
- }
47
- .reflection.class h2 {
48
- margin: 0;
45
+ .status-row.pass {
46
+ background: #008C32;
49
47
  }
50
-
51
- .reflection.method {
52
- padding: 2rem;
53
- margin-left: 1rem;
54
- margin-bottom: 1rem;
48
+ .status-row.fail {
49
+ background: #D04700;
55
50
  }
56
51
 
57
52
  /* Stats. */
@@ -63,14 +58,82 @@ li.panel {
63
58
  font-size: 3.5rem;
64
59
  font-family: 'Merriweather', serif;
65
60
  }
61
+
62
+ /* Class. */
63
+ .class {
64
+ padding: 2rem;
65
+ margin-bottom: 1rem;
66
+ }
67
+ .class:hover {
68
+ cursor: pointer;
69
+ }
70
+ .class h2 {
71
+ margin: 0;
72
+ }
73
+
74
+ /* Method. */
75
+ .method {
76
+ padding: 2rem;
77
+ margin-left: 1rem;
78
+ margin-bottom: 1rem;
79
+ }
80
+ .method:hover {
81
+ cursor: pointer;
82
+ }
66
83
  .method .stat {
67
84
  font-size: 2.5rem;
68
85
  }
69
86
 
70
- /* State. */
71
- .reflection.pass {
72
- background: #008C32;
87
+ /* Reflection. */
88
+ .reflection {
89
+ list-style: none;
90
+ margin-left: 2rem;
91
+ display: flex;
92
+ flex-direction: row;
93
+ align-items: center;
94
+ background: #EFEFEF;
95
+ padding: 0.5rem 1.5rem;
96
+ margin-bottom: 0.3rem;
73
97
  }
74
- .reflection.fail {
75
- background: #D04700;
98
+ .reflection .time {
99
+ color: #777777;
100
+ margin-right: 2rem;
101
+ }
102
+
103
+ .info {
104
+ display: flex;
105
+ flex-direction: row;
106
+ align-items: center;
107
+ padding: 0.5rem 1rem;
108
+ border: 1px solid #aaa;
109
+ border-radius: 5px;
110
+ }
111
+ .info:not(:last-child) {
112
+ margin-right: 0.5rem;
113
+ }
114
+ .info h4 {
115
+ margin: 0;
116
+ color: #777777;
117
+ font-size: 1.2rem;
118
+ font-weight: normal;
119
+ }
120
+
121
+ .info-items {
122
+ display: flex;
123
+ flex-direction: row;
124
+ }
125
+ .info-item {
126
+ padding-left: 1rem;
127
+ padding-right: 1rem;
128
+ border-right: 1px solid #ccc;
129
+ }
130
+ .info-item:last-of-type {
131
+ padding-right: 0;
132
+ border-right: 0;
133
+ }
134
+ .info-item strong {
135
+ padding-bottom: 0.1rem;
136
+ }
137
+ .info-item pre {
138
+ margin: 0;
76
139
  }
@@ -17,11 +17,20 @@
17
17
 
18
18
  <script>
19
19
 
20
- const STATUS = "s";
21
- const PASS = "p";
22
- const FAIL = "f";
23
-
24
- function getReflections() {
20
+ // Reflection keys.
21
+ const TIME = "t";
22
+ const INPUT = "i";
23
+ const OUTPUT = "o";
24
+ const TYPE = "T";
25
+ const COUNT = "C";
26
+ const VALUE = "V";
27
+ const STATUS = "s";
28
+ const MESSAGE = "m";
29
+ // Reflection values.
30
+ const PASS = "p";
31
+ const FAIL = "f";
32
+
33
+ function getData() {
25
34
 
26
35
  var reflections = JSON.parse(<%= @@reflekt_json %>);
27
36
  console.log("REFLECTIONS:");
@@ -87,12 +96,15 @@
87
96
  }
88
97
  }
89
98
 
90
- return { refs: results };
99
+ return {
100
+ reflections: reflections,
101
+ results: results
102
+ };
91
103
  }
92
104
 
93
105
  </script>
94
106
 
95
- <div class="container" x-data="getReflections()">
107
+ <div class="container" x-data="getData()">
96
108
 
97
109
  <div id="header">
98
110
  <svg id="logo" enable-background="new 0 0 500 500" viewBox="0 0 500 500" xmlns="http://www.w3.org/2000/svg">
@@ -100,29 +112,86 @@
100
112
  <path d="m178 76.5-53.1-44-117.9 139 116 112z" fill="#d04800"/>
101
113
  <path d="m190.4 467.5h115l57.5-168h-229z" fill="#0047d0" opacity=".7"/>
102
114
  <path d="m177 467.5-81-85-92-197 115 113z" fill="#d04800" opacity=".7"/>
103
- <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>
115
+ <g fill="#008c33"><path d="m322 76.5 53.1-44 118 139-116 112z"/>
116
+ <path d="m320 467.5 84-85 92-197-117 113z" opacity=".7"/>
117
+ </g>
104
118
  </svg>
105
119
  </div>
106
120
 
107
- <ul class="panels">
108
- <template x-for="[class_id, klass] in Object.entries(refs)" :key="class_id">
121
+ <ul class="classes">
122
+ <template x-for="[class_id, klass] in Object.entries(results)" :key="class_id">
109
123
 
110
- <li class="panel">
124
+ <li class="class-container">
111
125
 
112
- <div class="reflection class" x-bind:class="` ${ klass.status } `">
113
- <h2 x-text="` ${class_id}() `"></h2>
126
+ <div class="status-row class" x-bind:class="`${klass.status}`" @click="klass['show'] = !klass['show']" :aria-expanded="klass['show'] ? 'true' : 'false'" :class="{ 'active': klass['show'] }">
127
+ <h2 x-text="`${class_id}()`"></h2>
114
128
  <div class="stats">
115
- <div class="stat" x-text="` ${klass.stats.pass_rate.toFixed(2)}% `"></div>
129
+ <div class="stat" x-text="`${klass.stats.pass_rate.toFixed(2)}%`"></div>
116
130
  </div>
117
131
  </div>
118
132
 
119
- <ul class="reflections methods">
133
+ <ul class="methods" x-show="klass['show']">
120
134
  <template x-for="[method_id, method] in Object.entries(klass['methods'])" :key="method_id">
121
- <li class="reflection method" x-bind:class="` ${ method.status } `">
122
- <h3 x-text="` ${method_id}() `"></h3>
123
- <div class="stats">
124
- <div class="stat" x-text="` ${method.stats.pass_rate.toFixed(2)}% `"></div>
135
+ <li class="method-container">
136
+
137
+ <div class="status-row method" x-bind:class="`${method.status}`" @click="method['show'] = !method['show']" :aria-expanded="method['show'] ? 'true' : 'false'" :class="{ 'active': method['show'] }">
138
+ <h3 x-text="`${method_id}()`"></h3>
139
+ <div class="stats">
140
+ <div class="stat" x-text="`${method.stats.pass_rate.toFixed(2)}%`"></div>
141
+ </div>
125
142
  </div>
143
+
144
+ <ul class="reflections" x-show="method['show']">
145
+ <template x-for="[reflection_id, reflection] in Object.entries(reflections[class_id][method_id])">
146
+
147
+ <li class="reflection">
148
+
149
+ <div class="time" x-text="`${new Date(reflection.t * 1000).getFullYear()}/${new Date(reflection.t * 1000).getMonth() + 1}/${new Date(reflection.t * 1000).getDate()} ${new Date(reflection.t * 1000).getHours()}:${new Date(reflection.t * 1000).getMinutes()}:${new Date(reflection.t * 1000).getSeconds()}`"></div>
150
+
151
+ <template x-for="[input_id, input] in Object.entries(reflection.i)">
152
+
153
+ <div class="info">
154
+ <h4>Input</h4>
155
+ <div class="info-items">
156
+ <div class="info-item">
157
+ <strong>Type:</strong><div class="input" x-text="input.T"></div>
158
+ </div>
159
+ <template x-if="input.V != undefined">
160
+ <div class="info-item">
161
+ <strong>Value:</strong><pre><div class="output" x-text="input.V"></div></pre>
162
+ </div>
163
+ </template>
164
+ <template x-if="input.C != undefined">
165
+ <div class="info-item">
166
+ <strong>Count:</strong><div class="input" x-text="input.C"></div>
167
+ </div>
168
+ </template>
169
+ </div>
170
+ </div>
171
+
172
+ </template>
173
+
174
+ <div class="info">
175
+ <h4>Output</h4>
176
+ <div class="info-items">
177
+ <div class="info-item">
178
+ <strong>Type:</strong><div class="output" x-text="reflection.o.T"></div>
179
+ </div>
180
+ <template x-if="reflection.o.C != undefined">
181
+ <div class="info-item">
182
+ <strong>Count:</strong><div class="output" x-text="reflection.o.C"></div>
183
+ </div>
184
+ </template>
185
+ <div class="info-item">
186
+ <strong>Value:</strong><pre><div class="output" x-text="reflection.o.V"></div></pre>
187
+ </div>
188
+ </div>
189
+ </div>
190
+ </li>
191
+
192
+ </template>
193
+ </ul>
194
+
126
195
  </li>
127
196
  </template>
128
197
  </ul>
@@ -134,7 +203,7 @@
134
203
 
135
204
  </div>
136
205
 
137
- <script src="alpine.js"></script>
206
+ <script src="script.js"></script>
138
207
 
139
208
  </body>
140
209
 
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.7.1
4
+ version: 0.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maedi Prichard
@@ -31,7 +31,7 @@ extensions: []
31
31
  extra_rdoc_files: []
32
32
  files:
33
33
  - lib/reflekt.rb
34
- - lib/web/alpine.js
34
+ - lib/web/script.js
35
35
  - lib/web/style.css
36
36
  - lib/web/template.html.erb
37
37
  homepage: https://github.com/maedi/reflekt