Class: DevSystem::SignalShell::Trap

Inherits:
Object
  • Object
show all
Defined in:
lib/dev_system/subsystems/shell/shells/signal_shell.rb

Class Method Summary collapse

Instance Method Summary collapse

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

#callObject



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