Class: SmokeSignals::Condition
- Inherits:
-
Object
- Object
- SmokeSignals::Condition
- Defined in:
- lib/smoke_signals.rb
Overview
This is the base class for all conditions.
Instance Attribute Summary (collapse)
-
- (Object) nonce
Returns the value of attribute nonce.
Instance Method Summary (collapse)
-
- (Object) handle_by(handler)
When a Condition is signaled, this method is called by the internals of SmokeSignals to determine whether it should be handled by a given handler.
-
- (Object) rescue(return_value = nil)
This should only be called from within a signal handler.
-
- (Object) restart(name, *args)
This should only be called from within a signal handler.
-
- (Object) signal
Signals this Condition.
-
- (Object) signal!
Signals this Condition.
Instance Attribute Details
- (Object) nonce
Returns the value of attribute nonce
66 67 68 |
# File 'lib/smoke_signals.rb', line 66 def nonce @nonce end |
Instance Method Details
- (Object) handle_by(handler)
When a Condition is signaled, this method is called by the internals of SmokeSignals to determine whether it should be handled by a given handler.
If you override this method in subclasses of Condition, return a Proc taking the Condition as an argument that should be run to handle the signal. Return nil to ignore the signal.
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/smoke_signals.rb', line 103 def handle_by(handler) if handler.is_a?(Proc) # No pattern given, so handler applies to everything. handler else applies_to, handler_fn = handler applies = case applies_to when Proc applies_to.call(self) when Array applies_to.any? {|a| a === self } else applies_to === self end applies ? handler_fn : nil end end |
- (Object) rescue(return_value = nil)
This should only be called from within a signal handler. It unwinds the stack to the point where SmokeSignals::handle was called and returns from SmokeSignals::handle with the given return value.
83 84 85 |
# File 'lib/smoke_signals.rb', line 83 def rescue(return_value=nil) raise RescueException.new(self.nonce, return_value) end |
- (Object) restart(name, *args)
This should only be called from within a signal handler. It unwinds the stack up to the point where SmokeSignals::with_restarts was called establishing the given restart, calls the restart with the given arguments, and returns the restart's return value from SmokeSignals::with_restarts.
92 93 94 |
# File 'lib/smoke_signals.rb', line 92 def restart(name, *args) SmokeSignals.restart(name, *args) end |
- (Object) signal
Signals this Condition.
69 70 71 |
# File 'lib/smoke_signals.rb', line 69 def signal SmokeSignals.signal(self, false) end |
- (Object) signal!
Signals this Condition. If it is not rescued or restarted by a handler, UnhandledSignalError is raised.
75 76 77 |
# File 'lib/smoke_signals.rb', line 75 def signal! SmokeSignals.signal(self, true) end |