stud 0.0.7 → 0.0.8
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/stud/trap.rb +10 -5
- metadata +2 -2
data/lib/stud/trap.rb
CHANGED
@@ -1,20 +1,25 @@
|
|
1
1
|
module Stud
|
2
2
|
def self.trap(signal, &block)
|
3
3
|
@traps ||= Hash.new { |h,k| h[k] = [] }
|
4
|
-
@traps[signal] << block
|
5
4
|
|
6
|
-
if !@
|
5
|
+
if !@traps.include?(signal)
|
6
|
+
# First trap call for this signal, tell ruby to invoke us.
|
7
7
|
previous_trap = Signal::trap(signal) { simulate_signal(signal) }
|
8
8
|
# If there was a previous trap (via Kernel#trap) set, make sure we remember it.
|
9
9
|
if previous_trap.is_a?(Proc)
|
10
|
-
|
10
|
+
# MRI's default traps are "DEFAULT" string
|
11
|
+
# JRuby's default traps are Procs with a source_location of "(internal")
|
12
|
+
if RUBY_ENGINE != "jruby" || previous_trap.source_location.first != "(internal)"
|
13
|
+
@traps[signal] << previous_trap
|
14
|
+
end
|
11
15
|
end
|
12
|
-
|
13
|
-
@trapped = true
|
14
16
|
end
|
17
|
+
|
18
|
+
@traps[signal] << block
|
15
19
|
end
|
16
20
|
|
17
21
|
def self.simulate_signal(signal)
|
22
|
+
puts "Simulate: #{signal}"
|
18
23
|
@traps[signal].each(&:call)
|
19
24
|
end
|
20
25
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stud
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|