Class: DevSystem::SignalShell::Trap
- Inherits:
-
Object
- Object
- DevSystem::SignalShell::Trap
- Defined in:
- lib/dev_system/subsystems/shell/shells/signal_shell.rb
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(signal) ⇒ Trap
constructor
A new instance of Trap.
- #push(block) ⇒ Object
Constructor Details
#initialize(signal) ⇒ Trap
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/dev_system/subsystems/shell/shells/signal_shell.rb', line 31 def initialize(signal) @blocks = [] ::Signal.trap(signal) do puts "\nSignal.trap(#{signal.inspect})" puts "# Control-C pressed. #{@blocks.count} blocks to run..." if signal == "INT" call if signal == "INT" puts "# Exiting with status 1..." exit 1 end end end |
Class Method Details
.find(signal) ⇒ Object
26 27 28 29 |
# File 'lib/dev_system/subsystems/shell/shells/signal_shell.rb', line 26 def self.find(signal) @traps ||= {} @traps[signal] ||= new(signal) end |
Instance Method Details
#call ⇒ Object
46 47 48 49 50 |
# File 'lib/dev_system/subsystems/shell/shells/signal_shell.rb', line 46 def call @blocks.each do |block| block.call end end |
#push(block) ⇒ Object
44 |
# File 'lib/dev_system/subsystems/shell/shells/signal_shell.rb', line 44 def push (block) = @blocks.push block |