Module: Reflekt
- Defined in:
- lib/reflekt.rb
Overview
REFLEKT
Usage. Prepend to the class like so:
class ExampleClass
prepend Reflekt
Defined Under Namespace
Modules: SingletonClassMethods
Constant Summary
collapse
- REFLEKT_STATUS =
"s"
- REFLEKT_PASS =
"p"
- REFLEKT_FAIL =
"f"
- REFLEKT_MESSAGE =
"m"
- @@reflekt_clone_count =
5
Instance Method Summary
collapse
Instance Method Details
#initialize(*args) ⇒ Object
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
63
64
65
66
67
68
69
70
71
|
# File 'lib/reflekt.rb', line 23
def initialize(*args)
@reflekt_forked = false
@reflekt_clones = []
@reflekt_limit = 5
@reflekt_count = 0
self.class.instance_methods(false).each do |method|
self.define_singleton_method(method) do |*args|
if @reflekt_forked
if @reflekt_count < @reflekt_limit
unless self.class.deflekted?(method)
@reflekt_clones.each do |clone|
reflekt_action(clone, method, *args)
end
@@reflekt_db.write()
reflekt_render()
end
@reflekt_count = @reflekt_count + 1
end
end
super *args
end
end
super
reflekt_fork()
end
|
#reflekt_action(clone, method, *args) ⇒ Object
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
# File 'lib/reflekt.rb', line 83
def reflekt_action(clone, method, *args)
class_name = clone.class.to_s
method_name = method.to_s
new_args = []
args.each do |arg|
case arg
when Integer
new_args << rand(9999)
else
new_args << arg
end
end
begin
clone.send(method, *new_args)
reflection = { "time" => Time.now.to_i }
rescue StandardError => message
reflection[REFLEKT_STATUS] = REFLEKT_MESSAGE
reflection[REFLEKT_MESSAGE] = message
else
reflection[REFLEKT_STATUS] = REFLEKT_PASS
end
@@reflekt_db.get("#{class_name}.#{method_name}").push(reflection)
end
|
#reflekt_fork ⇒ Object
73
74
75
76
77
78
79
80
81
|
# File 'lib/reflekt.rb', line 73
def reflekt_fork()
@@reflekt_clone_count.times do |clone|
@reflekt_clones << self.clone
end
@reflekt_forked = true
end
|
#reflekt_render ⇒ Object
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
# File 'lib/reflekt.rb', line 120
def reflekt_render()
@@reflekt_json = File.read("#{@@reflekt_output_path}/db.json")
template = File.read("#{@@reflekt_path}/web/template.html.erb")
rendered = ERB.new(template).result(binding)
File.open("#{@@reflekt_output_path}/index.html", 'w+') do |f|
f.write rendered
end
javascript = File.read("#{@@reflekt_path}/web/alpine.js")
File.open("#{@@reflekt_output_path}/alpine.js", 'w+') do |f|
f.write javascript
end
stylesheet = File.read("#{@@reflekt_path}/web/style.css")
File.open("#{@@reflekt_output_path}/style.css", 'w+') do |f|
f.write stylesheet
end
end
|