reflekt 0.9.2 → 0.9.3

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: 21ac72b1a4f8bf9bd182f1d1ae5464d11aa87ab0f38c6fa418c9a3e73ff33a5d
4
- data.tar.gz: bfd3a381c930d910e3b293e835877712734eecc2a51c7949e7f4747b67377058
3
+ metadata.gz: d76793031a1fb34931c9c71500a45249951cc50dcd820be7ac2faf6df2b091d3
4
+ data.tar.gz: 5263bb832fff7b00d73496cee4f708b1355907f38e496dd96486ca0bbbd0efab
5
5
  SHA512:
6
- metadata.gz: e9b62612aa60d91bf591eae59c9797c97e9b54fdafd58d2785ed4fdfa8c7bc256cd288e13dd9e83d4fd8d11fbdbe043ce0660f6ba82878f8fd5eabb224d691b0
7
- data.tar.gz: 9a38959ce057bdf3f4e7e2091f0aa6666be940e356b5865952a7e9e7749958d77f8beb68d2fd8f9a252f047bb45bccc756b3f9af793c85e3031a4f0cab541c74
6
+ metadata.gz: 6d0a232b0fbc4cb944a8c19827da8bbe2962e4fc41b178e6b9ae99853c7f96d611d6b08b307313d8f8430af2e118933149e1772f3c3c125bd4f14eb70bf61b82
7
+ data.tar.gz: c5e439d83d26c7b9938b08ecfa466817e39cdf938a584012a86dd7ec0d2187f8ead6559c085874f8df5e1788567d9b57a847249ae1f20e76c03c67be58fea56d
@@ -0,0 +1,37 @@
1
+ ################################################################################
2
+ # ACCESSOR
3
+ #
4
+ # Access variables via one object to avoid polluting the caller class.
5
+ #
6
+ # Only 2 variables are not accessed via Accessor:
7
+ # - @reflection_counts on the instance
8
+ # - @@reflekt_skipped_methods on the instance's singleton class
9
+ ################################################################################
10
+
11
+ class Accessor
12
+
13
+ attr_accessor :setup
14
+ attr_accessor :db
15
+ attr_accessor :json
16
+ attr_accessor :stack
17
+ attr_accessor :rules
18
+ attr_accessor :path
19
+ attr_accessor :output_path
20
+ attr_accessor :reflect_amount
21
+ attr_accessor :reflection_limit
22
+
23
+ def initialize()
24
+
25
+ @setup = nil
26
+ @db = nil
27
+ @json = nil
28
+ @stack = nil
29
+ @rules = nil
30
+ @path = nil
31
+ @output_path = nil
32
+ @reflect_amount = nil
33
+ @reflection_limit = nil
34
+
35
+ end
36
+
37
+ end
@@ -1,6 +1,7 @@
1
1
  require 'set'
2
2
  require 'erb'
3
3
  require 'rowdb'
4
+ require 'Accessor'
4
5
  require 'Control'
5
6
  require 'Execution'
6
7
  require 'Reflection'
@@ -23,13 +24,6 @@ require 'ShadowStack'
23
24
 
24
25
  module Reflekt
25
26
 
26
- # The amount of reflections to create per method call.
27
- @@reflekt_reflect_amount = 2
28
-
29
- # Limit the amount of reflections that can be created per instance method.
30
- # A method called thousands of times doesn't need that many reflections.
31
- @@reflection_limit = 10
32
-
33
27
  def initialize(*args)
34
28
 
35
29
  @reflection_counts = {}
@@ -47,24 +41,24 @@ module Reflekt
47
41
  self.define_singleton_method(method) do |*args|
48
42
 
49
43
  # Don't reflect when limit reached.
50
- unless @reflection_counts[method] >= @@reflection_limit
44
+ unless @reflection_counts[method] >= @@reflekt.reflection_limit
51
45
 
52
46
  # Get current execution.
53
- execution = @@reflekt_stack.peek()
47
+ execution = @@reflekt.stack.peek()
54
48
 
55
49
  # When stack empty or past execution done reflecting.
56
50
  if execution.nil? || execution.has_finished_reflecting?
57
51
 
58
52
  # Create execution.
59
- execution = Execution.new(self, @@reflekt_reflect_amount)
60
- @@reflekt_stack.push(execution)
53
+ execution = Execution.new(self, @@reflekt.reflect_amount)
54
+ @@reflekt.stack.push(execution)
61
55
 
62
56
  end
63
57
 
64
58
  # Get ruler.
65
59
  # The method's ruler will not exist the first time the db generated.
66
- if @@reflekt_rules.key? execution.caller_class.to_s.to_sym
67
- ruler = @@reflekt_rules[execution.caller_class.to_s.to_sym][method.to_s]
60
+ if @@reflekt.rules.key? execution.caller_class.to_s.to_sym
61
+ ruler = @@reflekt.rules[execution.caller_class.to_s.to_sym][method.to_s]
68
62
  else
69
63
  ruler = nil
70
64
  end
@@ -86,7 +80,7 @@ module Reflekt
86
80
  control.reflect(*args)
87
81
 
88
82
  # Save control.
89
- @@reflekt_db.get("#{class_name}.#{method_name}.controls").push(control.result())
83
+ @@reflekt.db.get("#{class_name}.#{method_name}.controls").push(control.result())
90
84
 
91
85
  # Multiple reflections per execution.
92
86
  execution.reflections.each_with_index do |value, index|
@@ -100,12 +94,12 @@ module Reflekt
100
94
  @reflection_counts[method] = @reflection_counts[method] + 1
101
95
 
102
96
  # Save reflection.
103
- @@reflekt_db.get("#{class_name}.#{method_name}.reflections").push(reflection.result())
97
+ @@reflekt.db.get("#{class_name}.#{method_name}.reflections").push(reflection.result())
104
98
 
105
99
  end
106
100
 
107
101
  # Save results.
108
- @@reflekt_db.write()
102
+ @@reflekt.db.write()
109
103
 
110
104
  # Render results.
111
105
  reflekt_render()
@@ -133,24 +127,24 @@ module Reflekt
133
127
  def reflekt_render()
134
128
 
135
129
  # Get JSON.
136
- @@reflekt_json = File.read("#{@@reflekt_output_path}/db.json")
130
+ @@reflekt.json = File.read("#{@@reflekt.output_path}/db.json")
137
131
 
138
132
  # Save HTML.
139
- template = File.read("#{@@reflekt_path}/web/template.html.erb")
133
+ template = File.read("#{@@reflekt.path}/web/template.html.erb")
140
134
  rendered = ERB.new(template).result(binding)
141
- File.open("#{@@reflekt_output_path}/index.html", 'w+') do |f|
135
+ File.open("#{@@reflekt.output_path}/index.html", 'w+') do |f|
142
136
  f.write rendered
143
137
  end
144
138
 
145
139
  # Add JS.
146
- javascript = File.read("#{@@reflekt_path}/web/script.js")
147
- File.open("#{@@reflekt_output_path}/script.js", 'w+') do |f|
140
+ javascript = File.read("#{@@reflekt.path}/web/script.js")
141
+ File.open("#{@@reflekt.output_path}/script.js", 'w+') do |f|
148
142
  f.write javascript
149
143
  end
150
144
 
151
145
  # Add CSS.
152
- stylesheet = File.read("#{@@reflekt_path}/web/style.css")
153
- File.open("#{@@reflekt_output_path}/style.css", 'w+') do |f|
146
+ stylesheet = File.read("#{@@reflekt.path}/web/style.css")
147
+ File.open("#{@@reflekt.output_path}/style.css", 'w+') do |f|
154
148
  f.write stylesheet
155
149
  end
156
150
 
@@ -159,10 +153,14 @@ module Reflekt
159
153
  private
160
154
 
161
155
  def self.prepended(base)
156
+
162
157
  # Prepend class methods to the instance's singleton class.
163
158
  base.singleton_class.prepend(SingletonClassMethods)
164
159
 
165
- @@reflekt_setup ||= reflekt_setup_class
160
+ # Setup class.
161
+ @@reflekt = Accessor.new()
162
+ @@reflekt.setup ||= reflekt_setup_class
163
+
166
164
  end
167
165
 
168
166
  # Setup class.
@@ -173,33 +171,33 @@ module Reflekt
173
171
  $ENV[:reflekt] ||= $ENV[:reflekt] = {}
174
172
 
175
173
  # Set configuration.
176
- @@reflekt_path = File.dirname(File.realpath(__FILE__))
174
+ @@reflekt.path = File.dirname(File.realpath(__FILE__))
177
175
 
178
176
  # Build reflections directory.
179
177
  if $ENV[:reflekt][:output_path]
180
- @@reflekt_output_path = File.join($ENV[:reflekt][:output_path], 'reflections')
178
+ @@reflekt.output_path = File.join($ENV[:reflekt][:output_path], 'reflections')
181
179
  # Build reflections directory in current execution path.
182
180
  else
183
- @@reflekt_output_path = File.join(Dir.pwd, 'reflections')
181
+ @@reflekt.output_path = File.join(Dir.pwd, 'reflections')
184
182
  end
185
183
  # Create reflections directory.
186
- unless Dir.exist? @@reflekt_output_path
187
- Dir.mkdir(@@reflekt_output_path)
184
+ unless Dir.exist? @@reflekt.output_path
185
+ Dir.mkdir(@@reflekt.output_path)
188
186
  end
189
187
 
190
188
  # Create database.
191
- @@reflekt_db = Rowdb.new(@@reflekt_output_path + '/db.json')
192
- @@reflekt_db.defaults({ :reflekt => { :api_version => 1 }})
189
+ @@reflekt.db = Rowdb.new(@@reflekt.output_path + '/db.json')
190
+ @@reflekt.db.defaults({ :reflekt => { :api_version => 1 }})
193
191
 
194
192
  # Create shadow execution stack.
195
- @@reflekt_stack = ShadowStack.new()
193
+ @@reflekt.stack = ShadowStack.new()
196
194
 
197
195
  # Define rules.
198
196
  # TODO: Fix Rowdb.get(path) not returning data at path after Rowdb.push()?
199
- @@reflekt_rules = {}
200
- db = @@reflekt_db.value()
197
+ @@reflekt.rules = {}
198
+ db = @@reflekt.db.value()
201
199
  db.each do |class_name, class_values|
202
- @@reflekt_rules[class_name] = {}
200
+ @@reflekt.rules[class_name] = {}
203
201
  class_values.each do |method_name, method_values|
204
202
  next if method_values.nil?
205
203
  next unless method_values.class == Hash
@@ -209,11 +207,18 @@ module Reflekt
209
207
  ruler.load(method_values['controls'])
210
208
  ruler.train()
211
209
 
212
- @@reflekt_rules[class_name][method_name] = ruler
210
+ @@reflekt.rules[class_name][method_name] = ruler
213
211
  end
214
212
  end
215
213
  end
216
214
 
215
+ # The amount of reflections to create per method call.
216
+ @@reflekt.reflect_amount = 2
217
+
218
+ # Limit the amount of reflections that can be created per instance method.
219
+ # A method called thousands of times doesn't need that many reflections.
220
+ @@reflekt.reflection_limit = 10
221
+
217
222
  return true
218
223
  end
219
224
 
@@ -236,7 +241,7 @@ module Reflekt
236
241
  end
237
242
 
238
243
  def reflekt_limit(amount)
239
- @@reflection_limit = amount
244
+ @@reflekt.reflection_limit = amount
240
245
  end
241
246
 
242
247
  end
@@ -32,7 +32,7 @@
32
32
 
33
33
  function getData() {
34
34
 
35
- var data = JSON.parse(<%= @@reflekt_json %>);
35
+ var data = JSON.parse(<%= @@reflekt.json %>);
36
36
  var results = {};
37
37
 
38
38
  console.log("DATA:");
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.2
4
+ version: 0.9.3
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-07-22 00:00:00.000000000 Z
11
+ date: 2020-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rowdb
@@ -30,6 +30,7 @@ executables: []
30
30
  extensions: []
31
31
  extra_rdoc_files: []
32
32
  files:
33
+ - lib/Accessor.rb
33
34
  - lib/Control.rb
34
35
  - lib/Execution.rb
35
36
  - lib/Reflection.rb