activefacts-api 1.7.1 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/activefacts/tracer.rb +54 -26
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 99ba306878626910f3539a86a128e850c02ed902
|
4
|
+
data.tar.gz: 050b900183c93c6ba9227e6ccf2fb8329481b090
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a83fa68aceea56997e9fe409bab5aa4db70af7e34a85ba032a3e03064f63527f29336a6849d4356b1f252581769e6d962d763d92f0857a788d022200f6ea431
|
7
|
+
data.tar.gz: ecceb3e5b2f746258de072f105f88ac3b18bedf2c49b8755715cb74c9820d801ba9350e5ed95cfbfd2409437b0050b3ee792988437d73efc4732c939fbb8bb82
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.8.0
|
data/lib/activefacts/tracer.rb
CHANGED
@@ -3,31 +3,39 @@
|
|
3
3
|
#
|
4
4
|
# The trace() method supports indented tracing.
|
5
5
|
#
|
6
|
+
# Trace keys:
|
6
7
|
# The first argument is normally a symbol which is the key for related trace calls.
|
7
8
|
# Set the TRACE environment variable to enable it, or add trace.enable(:key) to a CLI.
|
9
|
+
# A call to trace without a first symbol argument is always enabled (as if by :all)
|
8
10
|
#
|
11
|
+
# Message arguments:
|
9
12
|
# Each subsequent argument is either
|
10
13
|
# - a String (or anything that can be join()ed), or
|
11
14
|
# - a Proc (or anything that can be called) that returns such a string.
|
12
15
|
# Proc arguments will be called only if the trace key is enabled.
|
13
16
|
# If the key is enabled (or not present) the Trace strings will be joined and emitted.
|
14
17
|
#
|
18
|
+
# Trace blocks:
|
15
19
|
# A block passed to the trace method will always be called, and trace will always return its value.
|
16
20
|
# Any trace emitted from within such a block will be indented if the current trace key is enabled.
|
17
21
|
#
|
18
|
-
#
|
19
|
-
#
|
22
|
+
# Special trace key options for nesting blocks:
|
23
|
+
# - A trace key ending in _ is enabled if the base key is enabled, but enables all
|
24
|
+
# nested trace calls whether or not their key is enabled.
|
25
|
+
# - A trace key ending in ? is enabled if the base key is enabled, but is emitted
|
26
|
+
# only if (and just before) the nested block emits a trace message
|
20
27
|
#
|
28
|
+
# Testing whether a trace key is enabled:
|
21
29
|
# A call to trace with a key but without a block will return true if the key is enabled
|
22
30
|
#
|
23
31
|
# A call to trace with no arguments returns the Tracer object itself.
|
24
32
|
#
|
25
|
-
# Built-in trace
|
33
|
+
# Built-in trace keys and behaviour:
|
26
34
|
# help - list (at exit) all trace keys that became available during the run
|
27
35
|
# all - enable all trace keys
|
28
|
-
# keys - display trace
|
36
|
+
# keys - display the trace key for every trace message (automatically enabled by :all)
|
29
37
|
# debug - prepare a Ruby debugger at the start of the run, so it has the full context available
|
30
|
-
# firstaid -
|
38
|
+
# firstaid - enter the debugger inside the Exception constructor so you can inspect the local context
|
31
39
|
# trap - trap SIGINT (^C) in a block that allows inspecting or continuing execution (not all debuggers support this)
|
32
40
|
# flame - use ruby-prof-flamegraph to display the performance profile as a flame graph using SVG
|
33
41
|
#
|
@@ -45,6 +53,7 @@ module ActiveFacts
|
|
45
53
|
@indent = 0 # Current nesting level of enabled trace blocks
|
46
54
|
@nested = false # Set when a block enables all enclosed tracing
|
47
55
|
@available = {} # Hash of available trace keys, accumulated during the run
|
56
|
+
@delayed = nil # A delayed message, emitted only if the enclosed block emits tracing
|
48
57
|
|
49
58
|
@keys = {}
|
50
59
|
if (e = ENV["TRACE"])
|
@@ -54,11 +63,11 @@ module ActiveFacts
|
|
54
63
|
|
55
64
|
def trace(*args, &block)
|
56
65
|
begin
|
57
|
-
old_indent, old_nested, enabled = @indent, @nested, show(*args)
|
58
|
-
#
|
59
|
-
block ? yield : (args.size == 0 ? self :
|
66
|
+
old_indent, old_nested, old_delayed, enabled = @indent, @nested, @delayed, show(*args)
|
67
|
+
# This monstrosity reduces the steps when single-stepping:
|
68
|
+
block ? yield : (args.size == 0 ? self : enabled)
|
60
69
|
ensure
|
61
|
-
@indent, @nested = old_indent, old_nested
|
70
|
+
@indent, @nested, @delayed = old_indent, old_nested, old_delayed
|
62
71
|
end
|
63
72
|
end
|
64
73
|
|
@@ -179,18 +188,28 @@ module ActiveFacts
|
|
179
188
|
|
180
189
|
private
|
181
190
|
def show(*args)
|
182
|
-
|
191
|
+
enabled_prefix = selected?(args)
|
183
192
|
|
184
193
|
# Emit the message if enabled or a parent is:
|
185
|
-
if args.size > 0
|
186
|
-
|
194
|
+
if enabled_prefix && args.size > 0
|
195
|
+
message =
|
196
|
+
"\##{enabled_prefix} " +
|
187
197
|
' '*@indent +
|
188
198
|
args.
|
189
|
-
|
199
|
+
map{|a| a.respond_to?(:call) ? a.call : a}.
|
190
200
|
join(' ')
|
201
|
+
|
202
|
+
if @delayed == true
|
203
|
+
@delayed = message # Arrange to display this message later, if necessary
|
204
|
+
elsif @delayed
|
205
|
+
puts @delayed # Display a delayed message, then the current one
|
206
|
+
puts message
|
207
|
+
else
|
208
|
+
puts message
|
209
|
+
end
|
191
210
|
end
|
192
|
-
@indent +=
|
193
|
-
|
211
|
+
@indent += (enabled_prefix ? 1 : 0)
|
212
|
+
!!enabled_prefix
|
194
213
|
end
|
195
214
|
|
196
215
|
def selected?(args)
|
@@ -198,9 +217,13 @@ module ActiveFacts
|
|
198
217
|
key =
|
199
218
|
if Symbol === args[0]
|
200
219
|
control = args.shift
|
201
|
-
|
220
|
+
case s = control.to_s
|
221
|
+
when /_\Z/ # Enable all nested trace calls
|
202
222
|
nested = true
|
203
|
-
s.sub(/_\Z/, '').to_sym
|
223
|
+
s.sub(/_\Z/, '').to_sym
|
224
|
+
when /\?\Z/ # Delay this message until a nested active trace
|
225
|
+
@delayed = true
|
226
|
+
s.sub(/\?\Z/, '').to_sym
|
204
227
|
else
|
205
228
|
control
|
206
229
|
end
|
@@ -208,15 +231,20 @@ module ActiveFacts
|
|
208
231
|
:all
|
209
232
|
end
|
210
233
|
|
211
|
-
@available[key] ||= key
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
234
|
+
@available[key] ||= key # Remember that this trace was requested, for help
|
235
|
+
@nested ||= nested # Activate nesting, if requested
|
236
|
+
if @nested || # This trace is enabled because it's in a nested block
|
237
|
+
@keys[key] || # This trace is enabled in its own right
|
238
|
+
@keys[:all] # This trace is enabled because all are
|
239
|
+
if @keys[:keys] || @keys[:all] # Use a formatting prefix?
|
240
|
+
enabled_prefix = " %-15s"%key
|
241
|
+
@keys[key] = enabled_prefix if @keys[key] == true # Save the formatting prefix
|
242
|
+
else
|
243
|
+
enabled_prefix = ''
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
enabled_prefix
|
220
248
|
end
|
221
249
|
|
222
250
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activefacts-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Clifford Heath
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rbtree-pure
|