stud 0.0.6 → 0.0.7

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.
Files changed (2) hide show
  1. data/lib/stud/trap.rb +38 -0
  2. metadata +3 -2
data/lib/stud/trap.rb ADDED
@@ -0,0 +1,38 @@
1
+ module Stud
2
+ def self.trap(signal, &block)
3
+ @traps ||= Hash.new { |h,k| h[k] = [] }
4
+ @traps[signal] << block
5
+
6
+ if !@trapped
7
+ previous_trap = Signal::trap(signal) { simulate_signal(signal) }
8
+ # If there was a previous trap (via Kernel#trap) set, make sure we remember it.
9
+ if previous_trap.is_a?(Proc)
10
+ @traps[signal] << previous_trap
11
+ end
12
+
13
+ @trapped = true
14
+ end
15
+ end
16
+
17
+ def self.simulate_signal(signal)
18
+ @traps[signal].each(&:call)
19
+ end
20
+ end
21
+
22
+ # Monkey-patch the main 'trap' stuff? This could be useful.
23
+ #module Signal
24
+ #def trap(signal, value=nil, &block)
25
+ #if value.nil?
26
+ #Stud.trap(signal, &block)
27
+ #else
28
+ ## do nothing?
29
+ #end
30
+ #end # def trap
31
+ #end
32
+ #
33
+ #module Kernel
34
+ #def trap(signal, value=nil, &block)
35
+ #Signal.trap(signal, value, &block)
36
+ #end
37
+ #end
38
+
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.6
4
+ version: 0.0.7
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-10-18 00:00:00.000000000 Z
12
+ date: 2012-11-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -54,6 +54,7 @@ files:
54
54
  - lib/stud/interval.rb
55
55
  - lib/stud/benchmark.rb
56
56
  - lib/stud/task.rb
57
+ - lib/stud/trap.rb
57
58
  - lib/stud/secret.rb
58
59
  - lib/stud/pool.rb
59
60
  - LICENSE