tricky_signals 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5bae01d6def11c743e015c04e98c535fcedffc7a
4
- data.tar.gz: 6566524445724705862fd73938ac86ce5c17fe3c
3
+ metadata.gz: c9fabd029343a2c7cbda95e01e474851296bf0ad
4
+ data.tar.gz: 98a3db8488f747fc20bd6825f16e057a57b276f4
5
5
  SHA512:
6
- metadata.gz: a0819793f214f9ebf5462447d138621afe780fb4ad4009caf0f5dcd49a0dba779961fc3a22f791d288e0d1310cea944b7288a29e2595fdccbed1402d56b5106c
7
- data.tar.gz: 0c61f0c2c319c6c5bdc2e45ccba1f69f5452c6565750ac01c2c0fca70a4a492f8291acac25f0e74fc92dd325d8c88b33d8a09e1087a27d3f5c87fb5084ee8e5b
6
+ metadata.gz: 77c4e0a7783d0852e3d03bb2d84ab1a40d36e54a3a0d8fbc2c2ab7dc5bc05105d171de42b85d73a5f17af5264039700981f28e71daaca1da2cdb9d8a230023f5
7
+ data.tar.gz: d99f6b523f9de6207c664d677f181d962d5cf9c800f68594c0bb8f86492ba436e63181508968e76ef83aa3fa9df01d74c15780840a9fb84593c5736361e801e0
@@ -2,9 +2,6 @@ require 'thread'
2
2
  require 'monitor.rb'
3
3
 
4
4
  class TrickySignals
5
- class Handlers
6
- end
7
-
8
5
  class << self
9
6
  def start!
10
7
  obj = new.start!
@@ -15,10 +12,6 @@ class TrickySignals
15
12
  obj
16
13
  end
17
14
  end
18
-
19
- def handlers_class
20
- const_get(:Handlers)
21
- end
22
15
  end
23
16
 
24
17
  include MonitorMixin
@@ -33,7 +26,7 @@ class TrickySignals
33
26
  fail "cannot start #{self}: already started!" if @started
34
27
  @started = true
35
28
 
36
- @handlers = self.class.handlers_class.new
29
+ @handlers = {}
37
30
  @previous = {}
38
31
  @io_thread = start_io
39
32
  self
@@ -59,22 +52,6 @@ class TrickySignals
59
52
  @started
60
53
  end
61
54
 
62
- def handlers
63
- synchronize do
64
- check_started!
65
- @handlers
66
- end
67
- end
68
-
69
- def setup_handlers
70
- fail 'you should pass a block to `setup_handlers`' unless block_given?
71
-
72
- synchronize do
73
- check_started!
74
- @handlers.instance_eval(&proc)
75
- end
76
- end
77
-
78
55
  def trap(signal, command = nil)
79
56
  synchronize do
80
57
  check_started!
@@ -137,11 +114,13 @@ class TrickySignals
137
114
  signal = input.chomp
138
115
 
139
116
  synchronize do
140
- handler = @handlers.public_method("handle_#{signal}")
141
- case handler.arity
142
- when 0 then handler.call
143
- when 1 then handler.call signal
144
- when 2 then handler.call signal, @previous[signal]
117
+ handler = @handlers[signal]
118
+ if handler
119
+ case handler.arity
120
+ when 0 then handler.call
121
+ when 1 then handler.call signal
122
+ when 2 then handler.call signal, @previous[signal]
123
+ end
145
124
  end
146
125
  end
147
126
  end
@@ -159,17 +138,14 @@ class TrickySignals
159
138
  end
160
139
 
161
140
  def trap_with_block(signal, &block)
162
- @handlers.define_singleton_method("handle_#{signal}", &block)
141
+ @handlers[signal] = block
163
142
  Signal.trap(signal) do
164
143
  @io_write.puts(signal)
165
144
  end
166
145
  end
167
146
 
168
147
  def trap_with_command(signal, command)
169
- sclass = @handlers.singleton_class
170
- if sclass.method_defined?(method_name_for(signal))
171
- sclass.send(:remove_method, method_name_for(signal))
172
- end
148
+ @handlers.delete signal
173
149
  Signal.trap(signal, command)
174
150
  end
175
151
 
@@ -192,10 +168,6 @@ class TrickySignals
192
168
  signal.to_s
193
169
  end
194
170
  end
195
-
196
- def method_name_for(signal)
197
- "handle_#{signal}"
198
- end
199
171
  end
200
172
 
201
173
  require 'tricky_signals/global'
@@ -1,3 +1,3 @@
1
1
  class TrickySignals
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tricky_signals
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladimir Kochnev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-09-14 00:00:00.000000000 Z
11
+ date: 2015-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler