rubybreaker 0.0.2 → 0.0.3
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.
- data/NEWS +6 -46
- data/README.md +30 -19
- data/TODO +22 -20
- data/VERSION +1 -1
- data/bin/rubybreaker +11 -2
- data/lib/rubybreaker.rb +31 -11
- data/lib/rubybreaker/debug.rb +5 -49
- data/lib/rubybreaker/{context.rb → debug/context.rb} +0 -0
- data/lib/rubybreaker/debug/debug.rb +61 -0
- data/lib/rubybreaker/{error.rb → debug/error.rb} +1 -1
- data/lib/rubybreaker/runtime.rb +3 -2
- data/lib/rubybreaker/runtime/inspector.rb +20 -13
- data/lib/rubybreaker/runtime/monitor.rb +21 -13
- data/lib/rubybreaker/runtime/object_wrapper.rb +3 -1
- data/lib/rubybreaker/runtime/type_system.rb +3 -2
- data/lib/rubybreaker/test/testcase.rb +0 -1
- data/lib/rubybreaker/type/type.rb +1 -1
- data/lib/rubybreaker/type/type_grammar.treetop +1 -1
- data/lib/rubybreaker/type/type_unparser.rb +1 -1
- data/lib/rubybreaker/util.rb +3 -11
- data/test/integrated/tc_both_broken_breakable.rb +27 -0
- data/test/ts_integrated.rb +1 -0
- data/webpage/index.html +30 -19
- data/webpage/rdoc/RubyBreaker.html +127 -10
- data/webpage/rdoc/RubyBreaker/Breakable.html +1 -5
- data/webpage/rdoc/RubyBreaker/Broken.html +2 -6
- data/webpage/rdoc/RubyBreaker/Broken/BrokenEigen.html +3 -6
- data/webpage/rdoc/RubyBreaker/Context.html +6 -10
- data/webpage/rdoc/RubyBreaker/Errors.html +2 -6
- data/webpage/rdoc/RubyBreaker/Errors/InternalError.html +3 -7
- data/webpage/rdoc/RubyBreaker/Errors/InvalidSubtypeCheck.html +3 -7
- data/webpage/rdoc/RubyBreaker/Errors/InvalidTypeConstruction.html +2 -6
- data/webpage/rdoc/RubyBreaker/Errors/SubtypeFailure.html +2 -6
- data/webpage/rdoc/RubyBreaker/Errors/TypeError.html +3 -7
- data/webpage/rdoc/RubyBreaker/Errors/UserError.html +3 -7
- data/webpage/rdoc/RubyBreaker/Main.html +33 -20
- data/webpage/rdoc/RubyBreaker/ObjectPosition.html +4 -8
- data/webpage/rdoc/RubyBreaker/Position.html +7 -11
- data/webpage/rdoc/RubyBreaker/RubyTypeUtils.html +1 -5
- data/webpage/rdoc/RubyBreaker/Runtime.html +1 -5
- data/webpage/rdoc/RubyBreaker/Runtime/Inspector.html +25 -18
- data/webpage/rdoc/RubyBreaker/Runtime/MethodInfo.html +1 -5
- data/webpage/rdoc/RubyBreaker/Runtime/Monitor.html +4 -8
- data/webpage/rdoc/RubyBreaker/Runtime/MonitorInstaller.html +20 -43
- data/webpage/rdoc/RubyBreaker/Runtime/MonitorSwitch.html +7 -11
- data/webpage/rdoc/RubyBreaker/Runtime/MonitorUtils.html +6 -10
- data/webpage/rdoc/RubyBreaker/Runtime/ObjectWrapper.html +7 -11
- data/webpage/rdoc/RubyBreaker/Runtime/Pluggable.html +1 -5
- data/webpage/rdoc/RubyBreaker/Runtime/TypePlaceholder.html +1 -5
- data/webpage/rdoc/RubyBreaker/Runtime/TypeSigParser.html +1 -5
- data/webpage/rdoc/RubyBreaker/Runtime/TypeSystem.html +8 -12
- data/webpage/rdoc/RubyBreaker/TestCase.html +1 -6
- data/webpage/rdoc/RubyBreaker/TypeComparer.html +1 -5
- data/webpage/rdoc/RubyBreaker/TypeDefs.html +1 -5
- data/webpage/rdoc/RubyBreaker/TypeDefs/AnyType.html +1 -5
- data/webpage/rdoc/RubyBreaker/TypeDefs/BlockType.html +1 -5
- data/webpage/rdoc/RubyBreaker/TypeDefs/DuckType.html +1 -5
- data/webpage/rdoc/RubyBreaker/TypeDefs/FusionType.html +1 -5
- data/webpage/rdoc/RubyBreaker/TypeDefs/MethodListType.html +1 -5
- data/webpage/rdoc/RubyBreaker/TypeDefs/MethodType.html +1 -5
- data/webpage/rdoc/RubyBreaker/TypeDefs/NilType.html +1 -5
- data/webpage/rdoc/RubyBreaker/TypeDefs/NominalType.html +1 -5
- data/webpage/rdoc/RubyBreaker/TypeDefs/OptionalType.html +1 -5
- data/webpage/rdoc/RubyBreaker/TypeDefs/OrType.html +1 -5
- data/webpage/rdoc/RubyBreaker/TypeDefs/SelfType.html +1 -5
- data/webpage/rdoc/RubyBreaker/TypeDefs/Type.html +1 -5
- data/webpage/rdoc/RubyBreaker/TypeDefs/VarLengthType.html +1 -5
- data/webpage/rdoc/RubyBreaker/TypeUnparser.html +1 -5
- data/webpage/rdoc/RubyBreaker/Typing.html +1 -5
- data/webpage/rdoc/RubyBreaker/{Utilities.html → Util.html} +8 -9
- data/webpage/rdoc/created.rid +15 -14
- data/webpage/rdoc/index.html +1 -5
- data/webpage/rdoc/js/search_index.js +1 -1
- data/webpage/rdoc/table_of_contents.html +22 -36
- metadata +9 -7
- data/webpage/rdoc/RubyBreaker/Debug.html +0 -411
- data/webpage/rdoc/RubyBreaker/Kernel.html +0 -259
data/lib/rubybreaker/runtime.rb
CHANGED
@@ -41,7 +41,7 @@ module RubyBreaker
|
|
41
41
|
end
|
42
42
|
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
# This module is included for "broken" classes.
|
46
46
|
module Broken
|
47
47
|
|
@@ -85,7 +85,8 @@ module RubyBreaker
|
|
85
85
|
meth_type.types << t
|
86
86
|
else
|
87
87
|
# then upgrade it
|
88
|
-
placeholder.meth_type_map[t.meth_name] =
|
88
|
+
placeholder.meth_type_map[t.meth_name] =
|
89
|
+
MethodListType.new([meth_type, t])
|
89
90
|
end
|
90
91
|
else
|
91
92
|
placeholder.meth_type_map[t.meth_name] = t
|
@@ -1,6 +1,6 @@
|
|
1
1
|
#--
|
2
|
-
# This file defines
|
3
|
-
# module.
|
2
|
+
# This file defines the type inspector which fetches the type information
|
3
|
+
# gathered or documented in a Breakable, Broken, or hybrid module.
|
4
4
|
|
5
5
|
require_relative "util"
|
6
6
|
require_relative "monitor"
|
@@ -9,24 +9,26 @@ module RubyBreaker
|
|
9
9
|
|
10
10
|
module Runtime
|
11
11
|
|
12
|
-
# This module inspects a Breakable module
|
13
|
-
#
|
12
|
+
# This module inspects a Breakable module, a Broken module, or a hybrid
|
13
|
+
# module to fetch the type information for each method.
|
14
14
|
module Inspector
|
15
15
|
|
16
|
-
# This method inspects the module for
|
17
|
-
# returns the method type or method list type for the given
|
18
|
-
#
|
19
|
-
#
|
16
|
+
# This method inspects the module for the type of the specified
|
17
|
+
# method. It returns the method type or method list type for the given
|
18
|
+
# method, by looking at, first, the placeholder for the Breakable
|
19
|
+
# side of the module, and then, the placeholder for the Broken side of
|
20
|
+
# the module. If no method exists or if there is no type information
|
21
|
+
# for the method, it returns nil.
|
20
22
|
def self.inspect_meth(mod, mname)
|
21
23
|
mname = mname.to_sym
|
22
24
|
if Breakable::TYPE_PLACEHOLDER_MAP.has_key?(mod)
|
23
25
|
placeholder = Breakable::TYPE_PLACEHOLDER_MAP[mod]
|
24
|
-
elsif Broken::TYPE_PLACEHOLDER_MAP.has_key?(mod)
|
25
|
-
placeholder = Broken::TYPE_PLACEHOLDER_MAP[mod]
|
26
|
-
else
|
27
|
-
# TODO
|
28
26
|
end
|
29
27
|
t = placeholder.meth_type_map[mname] if placeholder
|
28
|
+
if !t && Broken::TYPE_PLACEHOLDER_MAP.has_key?(mod)
|
29
|
+
placeholder = Broken::TYPE_PLACEHOLDER_MAP[mod]
|
30
|
+
t = placeholder.meth_type_map[mname] if placeholder
|
31
|
+
end
|
30
32
|
return t
|
31
33
|
end
|
32
34
|
|
@@ -56,10 +58,15 @@ module RubyBreaker
|
|
56
58
|
mtypes[im] = mtype if mtype
|
57
59
|
}
|
58
60
|
end
|
61
|
+
mm = Broken::TYPE_PLACEHOLDER_MAP[mod]
|
62
|
+
if mm
|
63
|
+
mm.meth_type_map.each_pair {|im,mtype|
|
64
|
+
mtypes[im] = mtype if mtype
|
65
|
+
}
|
66
|
+
end
|
59
67
|
return mtypes
|
60
68
|
end
|
61
69
|
|
62
|
-
|
63
70
|
end
|
64
71
|
|
65
72
|
end
|
@@ -6,9 +6,8 @@
|
|
6
6
|
|
7
7
|
dir = File.dirname(__FILE__)
|
8
8
|
require_relative "util"
|
9
|
-
require_relative "type_placeholder"
|
10
|
-
require_relative "../context"
|
11
9
|
require_relative "../debug"
|
10
|
+
require_relative "type_placeholder"
|
12
11
|
require_relative "pluggable"
|
13
12
|
require_relative "type_system"
|
14
13
|
|
@@ -56,12 +55,12 @@ module RubyBreaker
|
|
56
55
|
def initialize(); @switch = true end
|
57
56
|
|
58
57
|
def turn_on();
|
59
|
-
|
58
|
+
RubyBreaker.log("Switch turned on")
|
60
59
|
@switch = true;
|
61
60
|
end
|
62
61
|
|
63
62
|
def turn_off();
|
64
|
-
|
63
|
+
RubyBreaker.log("Switch turned off")
|
65
64
|
@switch = false;
|
66
65
|
end
|
67
66
|
|
@@ -120,7 +119,7 @@ module RubyBreaker
|
|
120
119
|
# this is what the renamed method
|
121
120
|
stub_meth_name = get_alt_meth_name(meth_name)
|
122
121
|
|
123
|
-
|
122
|
+
RubyBreaker.log("Route to #{stub_meth_name}", :debug, CONTEXT)
|
124
123
|
|
125
124
|
# short-circuit if switch was off--i.e., no monitoring
|
126
125
|
if !switch
|
@@ -143,7 +142,7 @@ module RubyBreaker
|
|
143
142
|
|
144
143
|
mm.monitor_before_method(obj, meth_info)
|
145
144
|
|
146
|
-
|
145
|
+
RubyBreaker.log("monitor_before_method ended")
|
147
146
|
|
148
147
|
# we are going to turn the switch back on
|
149
148
|
GLOBAL_MONITOR_SWITCH.turn_on()
|
@@ -197,7 +196,7 @@ module RubyBreaker
|
|
197
196
|
def self.rename_meth(recv, meth_name)
|
198
197
|
alt_meth_name = MonitorUtils.get_alt_meth_name(meth_name)
|
199
198
|
recv.module_eval("alias :\"#{alt_meth_name}\" :\"#{meth_name}\"")
|
200
|
-
|
199
|
+
RubyBreaker.log("Adding alternate method for #{meth_name}")
|
201
200
|
recv.module_eval <<-EOF
|
202
201
|
def #{meth_name}(*args, &blk)
|
203
202
|
RubyBreaker::Runtime::MonitorUtils.route(self,
|
@@ -210,18 +209,27 @@ module RubyBreaker
|
|
210
209
|
|
211
210
|
# Installs an module (class) monitor to the object.
|
212
211
|
def self.install_module_monitor(mod)
|
213
|
-
|
212
|
+
|
213
|
+
RubyBreaker.log("Installing module monitor for #{mod}")
|
214
|
+
|
214
215
|
Breakable::MONITOR_MAP[mod] = Monitor.new(mod, DEFAULT_TYPE_SYSTEM)
|
215
216
|
Breakable::TYPE_PLACEHOLDER_MAP[mod] = TypePlaceholder.new
|
217
|
+
|
216
218
|
meth_type_map = []
|
217
219
|
meths = mod.instance_methods(false)
|
220
|
+
|
221
|
+
# RubyBreaker now supports the hybrid of Breakable and Broken. Here,
|
222
|
+
# see if any methods are already broken.
|
223
|
+
broken_meth_type_map = Inspector.inspect_all(mod)
|
224
|
+
broken_meths = broken_meth_type_map.keys
|
225
|
+
|
218
226
|
meths.each do |m|
|
219
|
-
|
227
|
+
# As long as the method is not "Broken" yet, it is considered
|
228
|
+
# Breakable (if the module is declared to be Breakable).
|
229
|
+
unless broken_meths.include?(m)
|
230
|
+
self.rename_meth(mod,m)
|
231
|
+
end
|
220
232
|
end
|
221
|
-
Debug.feed_line()
|
222
|
-
end
|
223
|
-
|
224
|
-
def self.report(mod)
|
225
233
|
end
|
226
234
|
|
227
235
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
#--
|
2
2
|
# This program keeps track of every method call to a wrapped object.
|
3
3
|
|
4
|
+
require_relative "../debug"
|
5
|
+
|
4
6
|
module RubyBreaker
|
5
7
|
|
6
8
|
module Runtime
|
@@ -66,7 +68,7 @@ module RubyBreaker
|
|
66
68
|
|
67
69
|
# This method missing method redirects all other method calls.
|
68
70
|
def method_missing(mname,*args,&blk)
|
69
|
-
|
71
|
+
::RubyBreaker.log("Method_missing for #{mname}")
|
70
72
|
if GLOBAL_MONITOR_SWITCH.switch
|
71
73
|
@__rubybreaker_type.add_meth(mname)
|
72
74
|
retval = @__rubybreaker_obj.send(mname,*args,&blk)
|
@@ -10,6 +10,7 @@ require_relative "object_wrapper"
|
|
10
10
|
require_relative "type_placeholder"
|
11
11
|
require_relative "../type"
|
12
12
|
require_relative "../typing"
|
13
|
+
require_relative "../debug"
|
13
14
|
|
14
15
|
module RubyBreaker
|
15
16
|
|
@@ -192,7 +193,7 @@ module RubyBreaker
|
|
192
193
|
end
|
193
194
|
end
|
194
195
|
|
195
|
-
|
196
|
+
RubyBreaker.log("In module monitor_before #{meth_name}")
|
196
197
|
|
197
198
|
meth_type = meth_type_map[meth_name]
|
198
199
|
|
@@ -241,7 +242,7 @@ module RubyBreaker
|
|
241
242
|
args = meth_info.args
|
242
243
|
blk = meth_info.blk
|
243
244
|
|
244
|
-
|
245
|
+
RubyBreaker.log("In module monitor_after #{meth_name}")
|
245
246
|
|
246
247
|
meth_type_map = Breakable::TYPE_PLACEHOLDER_MAP[mod].meth_type_map
|
247
248
|
|
@@ -232,7 +232,7 @@ grammar TypeGrammar
|
|
232
232
|
pos = RubyBreaker::Position.get()
|
233
233
|
pos.col = interval.first
|
234
234
|
begin
|
235
|
-
mod_name = RubyBreaker::
|
235
|
+
mod_name = RubyBreaker::Util.camelize(text_value)
|
236
236
|
mod = eval mod_name
|
237
237
|
t = RubyBreaker::NominalType.new(mod,pos)
|
238
238
|
rescue
|
@@ -37,7 +37,7 @@ module RubyBreaker
|
|
37
37
|
# print method.
|
38
38
|
def self.unparse_pp(pp,t)
|
39
39
|
if t.instance_of?(NominalType)
|
40
|
-
tname =
|
40
|
+
tname = Util.underscore(t.mod)
|
41
41
|
tokens = tname.split("/")
|
42
42
|
tname = tokens.last if tokens.size > 1
|
43
43
|
pp.text(tname)
|
data/lib/rubybreaker/util.rb
CHANGED
@@ -4,7 +4,9 @@
|
|
4
4
|
|
5
5
|
module RubyBreaker
|
6
6
|
|
7
|
-
module
|
7
|
+
# This module has utility functions that are useful across all components
|
8
|
+
# in the project.
|
9
|
+
module Util
|
8
10
|
|
9
11
|
# File activesupport/lib/active_support/inflector/methods.rb, line 48
|
10
12
|
def self.underscore(camel_cased_word)
|
@@ -28,14 +30,4 @@ module RubyBreaker
|
|
28
30
|
|
29
31
|
end
|
30
32
|
|
31
|
-
# http://mentalized.net/journal/2010/04/02/suppress_warnings_from_ruby/
|
32
|
-
module Kernel
|
33
|
-
def suppress_warning
|
34
|
-
original_verbosity = $VERBOSE
|
35
|
-
$VERBOSE = nil
|
36
|
-
result = yield
|
37
|
-
$VERBOSE = original_verbosity
|
38
|
-
return result
|
39
|
-
end
|
40
|
-
end
|
41
33
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require_relative "../../lib/rubybreaker"
|
3
|
+
|
4
|
+
class IntegratedBothBrokenBreakableTest < Test::Unit::TestCase
|
5
|
+
include RubyBreaker
|
6
|
+
include RubyBreaker::TestCase
|
7
|
+
|
8
|
+
class A
|
9
|
+
include RubyBreaker::Breakable
|
10
|
+
include RubyBreaker::Broken
|
11
|
+
typesig("foo(fixnum[to_s]) -> string")
|
12
|
+
def foo(x); x.to_s end
|
13
|
+
def bar(x); x.to_sym end
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_both_broken_and_breakable
|
17
|
+
# A.new.foo(1)
|
18
|
+
A.new.bar("abc")
|
19
|
+
a_foo_meth_type = Runtime::Inspector.inspect_meth(A, :foo)
|
20
|
+
a_bar_meth_type = Runtime::Inspector.inspect_meth(A, :bar)
|
21
|
+
str = RubyBreaker::TypeUnparser.unparse(a_foo_meth_type)
|
22
|
+
assert_equal("foo(fixnum[to_s]) -> string", str)
|
23
|
+
str = RubyBreaker::TypeUnparser.unparse(a_bar_meth_type)
|
24
|
+
assert_equal("bar(string[to_sym]) -> symbol", str)
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
data/test/ts_integrated.rb
CHANGED
data/webpage/index.html
CHANGED
@@ -197,10 +197,20 @@ signature <code>bar(fixnum[to_s]) -> string</code>, which means it takes an o
|
|
197
197
|
has <code>Fixnum</code>'s <code>to_s</code> method and returns a string. More detail on the type
|
198
198
|
annotation language will be explained in later section.</p>
|
199
199
|
|
200
|
-
<
|
201
|
-
|
202
|
-
|
203
|
-
|
200
|
+
<h3>Hybrid of Breakable and Broken</h3>
|
201
|
+
|
202
|
+
<p>Starting from version 0.0.3, RubyBreaker allows a module to be declared as
|
203
|
+
<code>Breakable</code> and <code>Broken</code> at the same time. If a method has a corresponding
|
204
|
+
type signature (manually documented) somewhere, then RubyBreaker will not
|
205
|
+
monitor it during runtime. All other methods will be instrumented and
|
206
|
+
monitored by RubyBreaker.</p>
|
207
|
+
|
208
|
+
<h3>Class Methods</h3>
|
209
|
+
|
210
|
+
<p>It is possible to include <code>Breakable</code> and/or <code>Broken</code> in an eigen-class to
|
211
|
+
document class methods. To make this easier, RubyBreaker will automatically
|
212
|
+
support auto-documentation and manual documentation of class methods if the
|
213
|
+
original module is declared as <code>Breakable</code> and/or <code>Broken</code>,
|
204
214
|
respectively--that is, up to immediate eigen class level of a "nominal"
|
205
215
|
module. The following example shows how class methods can be
|
206
216
|
auto-documented and manually documented, respectively.</p>
|
@@ -221,11 +231,6 @@ class B
|
|
221
231
|
end
|
222
232
|
</code></pre>
|
223
233
|
|
224
|
-
<p>Keep in mind that <code>Broken</code> module always wins against <code>Breakable</code>. In other
|
225
|
-
words, if a module is declared as both <code>Broken</code> and <code>Breakable</code>, it is
|
226
|
-
treated as <code>Broken</code>. Future versions of RubyBreaker will support a hybrid of
|
227
|
-
the two modules, but it remains as a limitation in the current version.</p>
|
228
|
-
|
229
234
|
<h3>Program Entry Point</h3>
|
230
235
|
|
231
236
|
<p>In Ruby, as soon as a file is <code>require</code>d, the execution of that file begins.
|
@@ -301,8 +306,8 @@ and returns a <code>String</code> object. Note that these types are in lowercase
|
|
301
306
|
indicating they are objects and not modules or classes themselves.</p>
|
302
307
|
|
303
308
|
<p>There are several types that represent an object: nominal, duck, fusion,
|
304
|
-
nil, 'any', and block. Each type signature
|
305
|
-
or a method list type (explained below).</p>
|
309
|
+
nil, 'any', 'or', optional, variable-length, and block. Each type signature
|
310
|
+
itself represents a method type or a method list type (explained below).</p>
|
306
311
|
|
307
312
|
<h3>Nominal Type</h3>
|
308
313
|
|
@@ -355,6 +360,20 @@ other type is not a subtype of <code>?</code>. This becomes a bit complicated fo
|
|
355
360
|
method or block argument types because of their contra-variance
|
356
361
|
characteristic. Please refer to the section <em>Subtyping</em>.</p>
|
357
362
|
|
363
|
+
<h3>Or Type</h3>
|
364
|
+
|
365
|
+
<p>Any above types can be "or"ed together, using <code>||</code>, to represent an object
|
366
|
+
that can be either one or the other. It <em>does</em> not represent an object that
|
367
|
+
has to be both (which is not supported by RubyBreaker).</p>
|
368
|
+
|
369
|
+
<h3>Optional Argument Type and Variable-Length Argument Type</h3>
|
370
|
+
|
371
|
+
<p>Another useful features of Ruby are the optional argument type and the
|
372
|
+
variable-length argument type. The former represents an argument that has a
|
373
|
+
default value (and therefore does not have to be provided). The latter
|
374
|
+
represents zero or more arguments of the same type. These are denoted by
|
375
|
+
suffices, <code>?</code> and <code>*</code>, respectively.</p>
|
376
|
+
|
358
377
|
<h3>Block Type</h3>
|
359
378
|
|
360
379
|
<p>One of the Ruby's prominent features is the block argument. It allows
|
@@ -370,14 +389,6 @@ However, <em>keep in mind</em> that RubyBreaker <em>cannot</em> automatically do
|
|
370
389
|
block types due to <code>yield</code> being a language construct rather than a method,
|
371
390
|
which means it cannot be captured by meta-programming!</p>
|
372
391
|
|
373
|
-
<h3>Optional Argument Type and Variable-Length Argument Type</h3>
|
374
|
-
|
375
|
-
<p>Another useful features of Ruby are the optional argument type and the
|
376
|
-
variable-length argument type. The former represents an argument that has a
|
377
|
-
default value (and therefore does not have to be provided). The latter
|
378
|
-
represents zero or more arguments of the same type. These are denoted by
|
379
|
-
suffices, <code>?</code> and <code>*</code>, respectively.</p>
|
380
|
-
|
381
392
|
<h3>Method Type and Method List Types</h3>
|
382
393
|
|
383
394
|
<p>Method type is similar to the block type, but it represents an actual method
|
@@ -47,9 +47,9 @@
|
|
47
47
|
<nav id="file-list-section" class="section">
|
48
48
|
<h3 class="section-header">Defined In</h3>
|
49
49
|
<ul>
|
50
|
-
<li>lib/rubybreaker/context.rb
|
51
|
-
<li>lib/rubybreaker/debug.rb
|
52
|
-
<li>lib/rubybreaker/error.rb
|
50
|
+
<li>lib/rubybreaker/debug/context.rb
|
51
|
+
<li>lib/rubybreaker/debug/debug.rb
|
52
|
+
<li>lib/rubybreaker/debug/error.rb
|
53
53
|
<li>lib/rubybreaker/runtime/inspector.rb
|
54
54
|
<li>lib/rubybreaker/runtime/monitor.rb
|
55
55
|
<li>lib/rubybreaker/runtime/object_wrapper.rb
|
@@ -96,8 +96,14 @@
|
|
96
96
|
|
97
97
|
<ul class="link-list">
|
98
98
|
|
99
|
+
<li><a href="#method-c-error">::error</a>
|
100
|
+
|
101
|
+
<li><a href="#method-c-log">::log</a>
|
102
|
+
|
99
103
|
<li><a href="#method-c-monitor">::monitor</a>
|
100
104
|
|
105
|
+
<li><a href="#method-c-verbose">::verbose</a>
|
106
|
+
|
101
107
|
</ul>
|
102
108
|
</nav>
|
103
109
|
|
@@ -120,8 +126,6 @@
|
|
120
126
|
|
121
127
|
<li><a href="./RubyBreaker/Context.html">RubyBreaker::Context</a>
|
122
128
|
|
123
|
-
<li><a href="./RubyBreaker/Debug.html">RubyBreaker::Debug</a>
|
124
|
-
|
125
129
|
<li><a href="./RubyBreaker/Errors.html">RubyBreaker::Errors</a>
|
126
130
|
|
127
131
|
<li><a href="./RubyBreaker/Errors/InternalError.html">RubyBreaker::Errors::InternalError</a>
|
@@ -136,8 +140,6 @@
|
|
136
140
|
|
137
141
|
<li><a href="./RubyBreaker/Errors/UserError.html">RubyBreaker::Errors::UserError</a>
|
138
142
|
|
139
|
-
<li><a href="./RubyBreaker/Kernel.html">RubyBreaker::Kernel</a>
|
140
|
-
|
141
143
|
<li><a href="./RubyBreaker/Main.html">RubyBreaker::Main</a>
|
142
144
|
|
143
145
|
<li><a href="./RubyBreaker/ObjectPosition.html">RubyBreaker::ObjectPosition</a>
|
@@ -206,7 +208,7 @@
|
|
206
208
|
|
207
209
|
<li><a href="./RubyBreaker/Typing.html">RubyBreaker::Typing</a>
|
208
210
|
|
209
|
-
<li><a href="./RubyBreaker/
|
211
|
+
<li><a href="./RubyBreaker/Util.html">RubyBreaker::Util</a>
|
210
212
|
|
211
213
|
</ul>
|
212
214
|
</nav>
|
@@ -292,6 +294,81 @@ monitor.</p>
|
|
292
294
|
<h3 class="section-header">Public Class Methods</h3>
|
293
295
|
|
294
296
|
|
297
|
+
<div id="method-c-error" class="method-detail ">
|
298
|
+
|
299
|
+
<div class="method-heading">
|
300
|
+
<span class="method-name">error</span><span
|
301
|
+
class="method-args">(err, level=:error, &blk)</span>
|
302
|
+
<span class="method-click-advice">click to toggle source</span>
|
303
|
+
</div>
|
304
|
+
|
305
|
+
|
306
|
+
<div class="method-description">
|
307
|
+
|
308
|
+
<p>This method is for reporting an error to the user. It will immediately show
|
309
|
+
the error message but also log it.</p>
|
310
|
+
|
311
|
+
|
312
|
+
|
313
|
+
<div class="method-source-code" id="error-source">
|
314
|
+
<pre><span class="ruby-comment"># File lib/rubybreaker/debug/debug.rb, line 38</span>
|
315
|
+
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">error</span>(<span class="ruby-identifier">err</span>, <span class="ruby-identifier">level</span>=<span class="ruby-value">:error</span>, &<span class="ruby-identifier">blk</span>)
|
316
|
+
<span class="ruby-identifier">msg</span> = <span class="ruby-identifier">err</span>.<span class="ruby-identifier">to_s</span>
|
317
|
+
<span class="ruby-identifier">msg</span> = <span class="ruby-node">"#{msg} : #{yield}"</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">blk</span>
|
318
|
+
<span class="ruby-constant">STDOUT</span>.<span class="ruby-identifier">puts</span> <span class="ruby-node">"[#{level.to_s.upcase}] #{msg}"</span>
|
319
|
+
<span class="ruby-constant">LOGGER</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">level</span>, <span class="ruby-identifier">msg</span>) <span class="ruby-keyword">if</span> <span class="ruby-keyword">defined?</span>(<span class="ruby-constant">OPTIONS</span>) <span class="ruby-operator">&&</span> <span class="ruby-constant">OPTIONS</span>[<span class="ruby-value">:debug</span>]
|
320
|
+
<span class="ruby-keyword">end</span></pre>
|
321
|
+
</div><!-- error-source -->
|
322
|
+
|
323
|
+
</div>
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
|
328
|
+
</div><!-- error-method -->
|
329
|
+
|
330
|
+
|
331
|
+
<div id="method-c-log" class="method-detail ">
|
332
|
+
|
333
|
+
<div class="method-heading">
|
334
|
+
<span class="method-name">log</span><span
|
335
|
+
class="method-args">(str, level=:debug, context=nil, &blk)</span>
|
336
|
+
<span class="method-click-advice">click to toggle source</span>
|
337
|
+
</div>
|
338
|
+
|
339
|
+
|
340
|
+
<div class="method-description">
|
341
|
+
|
342
|
+
<p>This method logs a non-error (or error) message but with the provided
|
343
|
+
context.</p>
|
344
|
+
|
345
|
+
|
346
|
+
|
347
|
+
<div class="method-source-code" id="log-source">
|
348
|
+
<pre><span class="ruby-comment"># File lib/rubybreaker/debug/debug.rb, line 47</span>
|
349
|
+
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">log</span>(<span class="ruby-identifier">str</span>, <span class="ruby-identifier">level</span>=<span class="ruby-value">:debug</span>, <span class="ruby-identifier">context</span>=<span class="ruby-keyword">nil</span>, &<span class="ruby-identifier">blk</span>)
|
350
|
+
<span class="ruby-keyword">return</span> <span class="ruby-keyword">unless</span> <span class="ruby-keyword">defined?</span>(<span class="ruby-constant">OPTIONS</span>) <span class="ruby-operator">&&</span> <span class="ruby-constant">OPTIONS</span>[<span class="ruby-value">:debug</span>]
|
351
|
+
<span class="ruby-identifier">msg</span> = <span class="ruby-identifier">str</span>.<span class="ruby-identifier">to_s</span>
|
352
|
+
<span class="ruby-identifier">msg</span> = <span class="ruby-node">"#{msg} : #{yield}"</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">blk</span>
|
353
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">context</span>
|
354
|
+
<span class="ruby-identifier">output</span> = <span class="ruby-string">""</span>
|
355
|
+
<span class="ruby-identifier">pp</span> = <span class="ruby-constant">PrettyPrint</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">output</span>)
|
356
|
+
<span class="ruby-identifier">context</span>.<span class="ruby-identifier">format_with_msg</span>(<span class="ruby-identifier">pp</span>,<span class="ruby-identifier">msg</span>)
|
357
|
+
<span class="ruby-identifier">pp</span>.<span class="ruby-identifier">flush</span>
|
358
|
+
<span class="ruby-identifier">msg</span> = <span class="ruby-identifier">output</span>
|
359
|
+
<span class="ruby-keyword">end</span>
|
360
|
+
<span class="ruby-constant">LOGGER</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">level</span>, <span class="ruby-identifier">msg</span>)
|
361
|
+
<span class="ruby-keyword">end</span></pre>
|
362
|
+
</div><!-- log-source -->
|
363
|
+
|
364
|
+
</div>
|
365
|
+
|
366
|
+
|
367
|
+
|
368
|
+
|
369
|
+
</div><!-- log-method -->
|
370
|
+
|
371
|
+
|
295
372
|
<div id="method-c-monitor" class="method-detail ">
|
296
373
|
|
297
374
|
<div class="method-heading">
|
@@ -303,12 +380,13 @@ monitor.</p>
|
|
303
380
|
|
304
381
|
<div class="method-description">
|
305
382
|
|
306
|
-
<p>
|
383
|
+
<p>This is the manual indicator for the program entry point. It simply
|
384
|
+
redirects to the monitor setup code.</p>
|
307
385
|
|
308
386
|
|
309
387
|
|
310
388
|
<div class="method-source-code" id="monitor-source">
|
311
|
-
<pre><span class="ruby-comment"># File lib/rubybreaker.rb, line
|
389
|
+
<pre><span class="ruby-comment"># File lib/rubybreaker.rb, line 229</span>
|
312
390
|
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">monitor</span>()
|
313
391
|
<span class="ruby-constant">Main</span>.<span class="ruby-identifier">setup</span>()
|
314
392
|
<span class="ruby-keyword">end</span></pre>
|
@@ -322,6 +400,45 @@ monitor.</p>
|
|
322
400
|
</div><!-- monitor-method -->
|
323
401
|
|
324
402
|
|
403
|
+
<div id="method-c-verbose" class="method-detail ">
|
404
|
+
|
405
|
+
<div class="method-heading">
|
406
|
+
<span class="method-name">verbose</span><span
|
407
|
+
class="method-args">(str) { || ... }</span>
|
408
|
+
<span class="method-click-advice">click to toggle source</span>
|
409
|
+
</div>
|
410
|
+
|
411
|
+
|
412
|
+
<div class="method-description">
|
413
|
+
|
414
|
+
<p>This method will display verbose message. It is not for debugging but to
|
415
|
+
inform users of each stage in the analysis.</p>
|
416
|
+
|
417
|
+
|
418
|
+
|
419
|
+
<div class="method-source-code" id="verbose-source">
|
420
|
+
<pre><span class="ruby-comment"># File lib/rubybreaker/debug/debug.rb, line 24</span>
|
421
|
+
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">verbose</span>(<span class="ruby-identifier">str</span>, &<span class="ruby-identifier">blk</span>)
|
422
|
+
<span class="ruby-keyword">return</span> <span class="ruby-keyword">unless</span> <span class="ruby-keyword">defined?</span>(<span class="ruby-constant">OPTIONS</span>) <span class="ruby-operator">&&</span> (<span class="ruby-constant">OPTIONS</span>[<span class="ruby-value">:verbose</span>] <span class="ruby-operator">||</span> <span class="ruby-constant">OPTIONS</span>[<span class="ruby-value">:debug</span>])
|
423
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">blk</span>
|
424
|
+
<span class="ruby-identifier">msg</span> = <span class="ruby-keyword">yield</span>
|
425
|
+
<span class="ruby-identifier">msg</span> = <span class="ruby-node">"#{str} : #{msg}"</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">str</span>
|
426
|
+
<span class="ruby-keyword">else</span>
|
427
|
+
<span class="ruby-identifier">msg</span> = <span class="ruby-identifier">str</span>
|
428
|
+
<span class="ruby-keyword">end</span>
|
429
|
+
<span class="ruby-constant">STDOUT</span>.<span class="ruby-identifier">puts</span> <span class="ruby-identifier">msg</span> <span class="ruby-keyword">if</span> <span class="ruby-constant">OPTIONS</span>[<span class="ruby-value">:verbose</span>]
|
430
|
+
<span class="ruby-constant">LOGGER</span>.<span class="ruby-identifier">info</span> <span class="ruby-identifier">msg</span> <span class="ruby-keyword">if</span> <span class="ruby-constant">OPTIONS</span>[<span class="ruby-value">:debug</span>]
|
431
|
+
<span class="ruby-keyword">end</span></pre>
|
432
|
+
</div><!-- verbose-source -->
|
433
|
+
|
434
|
+
</div>
|
435
|
+
|
436
|
+
|
437
|
+
|
438
|
+
|
439
|
+
</div><!-- verbose-method -->
|
440
|
+
|
441
|
+
|
325
442
|
</section><!-- public-class-method-details -->
|
326
443
|
|
327
444
|
</section><!-- 5Buntitled-5D -->
|