Class: Tap::Signals::Load

Inherits:
Tap::Signal show all
Includes:
Utils
Defined in:
lib/tap/signals/load.rb

Instance Attribute Summary

Attributes inherited from Tap::Signal

#block, #obj

Instance Method Summary collapse

Methods included from Utils

set_env, sh, sh_escape, shellsplit, with_env

Methods inherited from Tap::Signal

#initialize, #inspect

Constructor Details

This class inherits a constructor from Tap::Signal

Instance Method Details

#call(args) ⇒ Object



8
9
10
11
# File 'lib/tap/signals/load.rb', line 8

def call(args)
  args.each {|path| process(path) }
  obj
end

#each_signal(io) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/tap/signals/load.rb', line 25

def each_signal(io)
  offset = -1 * ($/.length + 1)

  carryover = nil
  io.each_line do |line|
    if line[offset] == ?\\
      carryover ||= []
      carryover << line[0, line.length + offset]
      carryover << $/
      next
    end

    if carryover
      carryover << line
      line = carryover.join
      carryover = nil
    end

    sig, *args = shellsplit(line)
    yield(sig, args) if sig
  end
end

#process(path) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/tap/signals/load.rb', line 13

def process(path)
  if File.exists?(path)
    File.open(path) do |io|
      each_signal(io) do |sig, args|
        obj.signal(sig).call(args)
      end
    end
  end
  
  obj
end