Class: InterruptHandler
- Inherits:
-
Object
- Object
- InterruptHandler
- Includes:
- Singleton
- Defined in:
- lib/overcommit/interrupt_handler.rb
Overview
Provides a handler for interrupt signals (SIGINT), allowing the application to finish what it’s currently working on.
Instance Attribute Summary collapse
-
#isolate_signals ⇒ Object
Returns the value of attribute isolate_signals.
-
#signal_received ⇒ Object
Returns the value of attribute signal_received.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ InterruptHandler
constructor
A new instance of InterruptHandler.
Constructor Details
#initialize ⇒ InterruptHandler
Returns a new instance of InterruptHandler.
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/overcommit/interrupt_handler.rb', line 10 def initialize self.isolate_signals = false self.signal_received = false Signal.trap('INT') do if isolate_signals self.signal_received = true else raise Interrupt end end end |
Instance Attribute Details
#isolate_signals ⇒ Object
Returns the value of attribute isolate_signals.
8 9 10 |
# File 'lib/overcommit/interrupt_handler.rb', line 8 def isolate_signals @isolate_signals end |
#signal_received ⇒ Object
Returns the value of attribute signal_received.
8 9 10 |
# File 'lib/overcommit/interrupt_handler.rb', line 8 def signal_received @signal_received end |
Class Method Details
.disable! ⇒ Object
24 25 26 |
# File 'lib/overcommit/interrupt_handler.rb', line 24 def disable! instance.isolate_signals = false end |
.enable! ⇒ Object
28 29 30 |
# File 'lib/overcommit/interrupt_handler.rb', line 28 def enable! instance.isolate_signals = true end |
.isolate_from_interrupts ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/overcommit/interrupt_handler.rb', line 32 def isolate_from_interrupts instance.signal_received = false instance.isolate_signals = true result = yield instance.isolate_signals = false result end |
.signal_received? ⇒ Boolean
40 41 42 |
# File 'lib/overcommit/interrupt_handler.rb', line 40 def signal_received? instance.signal_received end |