require 'trapper/version'

class Trapper
  def initialize(options = {}, &block)
    @kernel = options[:kernel] || Kernel

    Signal.trap('TERM') do
      $stderr.puts 'Caught SIGTERM. Exiting...'
      block.call
      @kernel.exit(1)
    end

    Signal.trap('INT') do
      $stderr.puts 'Caught SIGINT. Shutting down...'
      Process.kill 'TERM', Process.pid
    end
  end
end

