Module: Tap::Signals

Extended by:
ModuleMethods
Included in:
App, App::Api, Env
Defined in:
lib/tap/signals.rb,
lib/tap/signals/help.rb,
lib/tap/signals/load.rb,
lib/tap/signals/configure.rb,
lib/tap/signals/class_methods.rb,
lib/tap/signals/module_methods.rb

Overview

Signals is a module providing signaling capbilities for objects. Signals are effectively bound to methods with pre-processing that allows inputs from the command line (ie an ARGV) or from interfaces like HTTP that commonly produce a parameters hash.

Defined Under Namespace

Modules: ClassMethods, ModuleMethods Classes: Configure, Help, Load

Instance Method Summary collapse

Methods included from ModuleMethods

included

Instance Method Details

#sig(signal) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/tap/signals.rb', line 35

def sig(signal)
  signal = signal.class
  signals.each_pair do |sig, value|
    return sig if value == signal
  end
  nil
end

#signal(sig, &block) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/tap/signals.rb', line 21

def signal(sig, &block)
  sig = sig.to_s
  unless signal = signals[sig]
    raise "unknown signal: #{sig} (#{self.class})"
  end
  
  signal.new(self, &block)
end

#signal?(sig) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
33
# File 'lib/tap/signals.rb', line 30

def signal?(sig)
  sig = sig.to_s
  signals.has_key?(sig.to_s)
end

#signalsObject



14
15
16
17
18
19
# File 'lib/tap/signals.rb', line 14

def signals
  # memoization here is tempting, but a bad idea because the signals must
  # be recalculated in case of added modules.  see cache_signals for a
  # better way.
  self.class.signals
end