tattletail 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/lib/tattletail.rb +14 -65
- data/lib/tattletail/demo.rb +98 -0
- data/lib/tattletail/version.rb +1 -1
- metadata +9 -8
data/lib/tattletail.rb
CHANGED
@@ -7,6 +7,7 @@ module Tattletail
|
|
7
7
|
COLORS = { :count => '00a0b0',
|
8
8
|
:file => '444',
|
9
9
|
:context => '999',
|
10
|
+
:exception => 'f00',
|
10
11
|
:self => '793A57',
|
11
12
|
:method => 'fff',
|
12
13
|
:args => 'EB6841',
|
@@ -109,6 +110,10 @@ module Tattletail
|
|
109
110
|
end
|
110
111
|
end
|
111
112
|
|
113
|
+
def self.exception_str exception, indent_str
|
114
|
+
"#{exception.class.name}: #{exception.message.to_s}".color(COLORS[:exception]).bold.underline
|
115
|
+
end
|
116
|
+
|
112
117
|
def tattle_on(*method_names)
|
113
118
|
method_names.each do |method_name|
|
114
119
|
if class_method? method_name
|
@@ -189,6 +194,7 @@ private
|
|
189
194
|
|
190
195
|
Tattletail.indent
|
191
196
|
result = nil
|
197
|
+
begin
|
192
198
|
seconds = Benchmark.realtime { result = #{original_method}(*args, &blk) }
|
193
199
|
time_str = Tattletail.time_str(seconds)
|
194
200
|
result_str = Tattletail.result_str(result, indent_str)
|
@@ -202,6 +208,14 @@ private
|
|
202
208
|
puts indent_str + " " + time_str
|
203
209
|
|
204
210
|
result
|
211
|
+
rescue Exception => e
|
212
|
+
Tattletail.outdent
|
213
|
+
exception_str = Tattletail.exception_str(e, indent_str)
|
214
|
+
puts cont_indent_str if Tattletail.indent_changed?
|
215
|
+
puts end_indent_str + count_str + self_str + "." + method_str + " ⊢ " + exception_str
|
216
|
+
Tattletail.remember_indent
|
217
|
+
raise e
|
218
|
+
end
|
205
219
|
end
|
206
220
|
EOF
|
207
221
|
end
|
@@ -213,68 +227,3 @@ Tattletail.reset
|
|
213
227
|
class Object
|
214
228
|
extend Tattletail
|
215
229
|
end
|
216
|
-
|
217
|
-
class Fib
|
218
|
-
def no_args
|
219
|
-
5
|
220
|
-
end
|
221
|
-
tattle_on :no_args
|
222
|
-
|
223
|
-
def fib x
|
224
|
-
return 1 if x <= 2
|
225
|
-
fib(x - 1) + fib(x - 2)
|
226
|
-
end
|
227
|
-
tattle_on_instance_method :fib
|
228
|
-
|
229
|
-
def self.fib x
|
230
|
-
return 1 if x <= 2
|
231
|
-
fib(x - 1) + fib(x - 2)
|
232
|
-
end
|
233
|
-
tattle_on :fib
|
234
|
-
|
235
|
-
def self.find x
|
236
|
-
return 1 if x <= 2
|
237
|
-
find(x - 1) + find(x - 2)
|
238
|
-
end
|
239
|
-
tattle_on_class_method :find
|
240
|
-
|
241
|
-
def find x
|
242
|
-
x * 2
|
243
|
-
end
|
244
|
-
tell_on_instance_method :find
|
245
|
-
|
246
|
-
def fib_block &blk
|
247
|
-
fib yield
|
248
|
-
end
|
249
|
-
tell_on :fib_block
|
250
|
-
end
|
251
|
-
|
252
|
-
module Merge
|
253
|
-
extend Tattletail
|
254
|
-
|
255
|
-
def self.sample_array
|
256
|
-
[3,7,5,1,2,9,8,0,2,3,5,2,4,1,6,7,8,4,6,2,1]
|
257
|
-
end
|
258
|
-
|
259
|
-
def self.mergesort(list = sample_array)
|
260
|
-
return list if list.size <= 1
|
261
|
-
mid = list.size / 2
|
262
|
-
left = list[0, mid]
|
263
|
-
right = list[mid, list.size]
|
264
|
-
merge(mergesort(left), mergesort(right))
|
265
|
-
end
|
266
|
-
tattle_on :mergesort
|
267
|
-
|
268
|
-
def self.merge(left, right)
|
269
|
-
sorted = []
|
270
|
-
until left.empty? or right.empty?
|
271
|
-
if left.first <= right.first
|
272
|
-
sorted << left.shift
|
273
|
-
else
|
274
|
-
sorted << right.shift
|
275
|
-
end
|
276
|
-
end
|
277
|
-
sorted.concat(left).concat(right)
|
278
|
-
end
|
279
|
-
tattle_on :merge
|
280
|
-
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'tattletail'
|
2
|
+
|
3
|
+
module Tattletail
|
4
|
+
class Fib
|
5
|
+
def no_args
|
6
|
+
5
|
7
|
+
end
|
8
|
+
tattle_on :no_args
|
9
|
+
|
10
|
+
def fib x
|
11
|
+
return 1 if x <= 2
|
12
|
+
fib(x - 1) + fib(x - 2)
|
13
|
+
end
|
14
|
+
tattle_on_instance_method :fib
|
15
|
+
|
16
|
+
def self.fib x
|
17
|
+
return 1 if x <= 2
|
18
|
+
fib(x - 1) + fib(x - 2)
|
19
|
+
end
|
20
|
+
tattle_on :fib
|
21
|
+
|
22
|
+
def self.find x
|
23
|
+
return 1 if x <= 2
|
24
|
+
find(x - 1) + find(x - 2)
|
25
|
+
end
|
26
|
+
tattle_on_class_method :find
|
27
|
+
|
28
|
+
def find x
|
29
|
+
x * 2
|
30
|
+
end
|
31
|
+
tell_on_instance_method :find
|
32
|
+
|
33
|
+
def fib_block &blk
|
34
|
+
fib yield
|
35
|
+
end
|
36
|
+
tell_on :fib_block
|
37
|
+
|
38
|
+
def fib_raise n
|
39
|
+
raise 'This method always raises a generic exception'
|
40
|
+
end
|
41
|
+
tell_on :fib_raise
|
42
|
+
|
43
|
+
def fib_missing n
|
44
|
+
foo n
|
45
|
+
end
|
46
|
+
tell_on :fib_missing
|
47
|
+
|
48
|
+
def raise_test
|
49
|
+
5.times do |n|
|
50
|
+
if n % 2 == 0
|
51
|
+
fib n
|
52
|
+
else
|
53
|
+
begin
|
54
|
+
if n % 4 == 1
|
55
|
+
fib_raise n
|
56
|
+
else
|
57
|
+
fib_missing n
|
58
|
+
end
|
59
|
+
rescue Exception => e
|
60
|
+
e
|
61
|
+
end
|
62
|
+
n
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
tell_on :raise_test
|
67
|
+
end
|
68
|
+
|
69
|
+
module Merge
|
70
|
+
extend Tattletail
|
71
|
+
|
72
|
+
def self.sample_array
|
73
|
+
[3,7,5,1,2,9,8,0,2,3,5,2,4,1,6,7,8,4,6,2,1]
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.mergesort(list = sample_array)
|
77
|
+
return list if list.size <= 1
|
78
|
+
mid = list.size / 2
|
79
|
+
left = list[0, mid]
|
80
|
+
right = list[mid, list.size]
|
81
|
+
merge(mergesort(left), mergesort(right))
|
82
|
+
end
|
83
|
+
tattle_on :mergesort
|
84
|
+
|
85
|
+
def self.merge(left, right)
|
86
|
+
sorted = []
|
87
|
+
until left.empty? or right.empty?
|
88
|
+
if left.first <= right.first
|
89
|
+
sorted << left.shift
|
90
|
+
else
|
91
|
+
sorted << right.shift
|
92
|
+
end
|
93
|
+
end
|
94
|
+
sorted.concat(left).concat(right)
|
95
|
+
end
|
96
|
+
tattle_on :merge
|
97
|
+
end
|
98
|
+
end
|
data/lib/tattletail/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tattletail
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,12 +9,12 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
12
|
+
date: 2011-09-17 00:00:00.000000000 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rspec
|
17
|
-
requirement: &
|
17
|
+
requirement: &2161652420 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :development
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *2161652420
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: fuubar
|
28
|
-
requirement: &
|
28
|
+
requirement: &2161652000 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *2161652000
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: colorful
|
39
|
-
requirement: &
|
39
|
+
requirement: &2161651580 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ! '>='
|
@@ -44,7 +44,7 @@ dependencies:
|
|
44
44
|
version: '0'
|
45
45
|
type: :runtime
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *2161651580
|
48
48
|
description: Provides a method to watch specific methods and print them when they
|
49
49
|
are called
|
50
50
|
email:
|
@@ -59,6 +59,7 @@ files:
|
|
59
59
|
- README
|
60
60
|
- Rakefile
|
61
61
|
- lib/tattletail.rb
|
62
|
+
- lib/tattletail/demo.rb
|
62
63
|
- lib/tattletail/version.rb
|
63
64
|
- tattletail.gemspec
|
64
65
|
has_rdoc: true
|