Class: PBSimply::Hooks::HooksHolder

Inherits:
Object
  • Object
show all
Defined in:
lib/pbsimply/hooks.rb

Overview

Timing object class.

Direct Known Subclasses

HooksHolderPre

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ HooksHolder

Returns a new instance of HooksHolder.



10
11
12
13
# File 'lib/pbsimply/hooks.rb', line 10

def initialize name
  @name = name
  @hooks = []
end

Instance Method Details

#<<(proc) ⇒ Object



15
16
17
# File 'lib/pbsimply/hooks.rb', line 15

def <<(proc)
  @hooks << proc
end

#add(&proc) ⇒ Object



19
20
21
# File 'lib/pbsimply/hooks.rb', line 19

def add(&proc)
  @hooks << proc
end

#cmd(*cmdarg) ⇒ Object

Invoke command updating files



24
25
26
27
28
29
# File 'lib/pbsimply/hooks.rb', line 24

def cmd(*cmdarg)
  proc = ->(arg) do
    system(*cmdarg)
  end
  self << proc
end

#run(arg) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/pbsimply/hooks.rb', line 31

def run(arg)
  STDERR.puts "Hooks processing (#{@name})"
  @hooks.each_with_index do |proc, index|
    STDERR.puts "Hooks[#{index}]"
    begin
      proc.(arg)
    rescue
      STDERR.puts "*** HOOKS PROC ERROR ***"
      raise
    end
  end
end