Class: KnifeSantoku::Callback

Inherits:
Object
  • Object
show all
Includes:
Chef::Mixin::FromFile
Defined in:
lib/knife_santoku/callback.rb

Instance Method Summary collapse

Constructor Details

#initialize(file, notifier, argv) ⇒ Callback

Returns a new instance of Callback.



9
10
11
12
13
# File 'lib/knife_santoku/callback.rb', line 9

def initialize(file, notifier, argv)
  @file = file
  @notifier = notifier
  @argv = argv.join(" ")
end

Instance Method Details

#match(regexp, &proc) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/knife_santoku/callback.rb', line 19

def match(regexp, &proc)
  matches = regexp.match(@argv)

  if (matches != nil and matches.length > 1)

    # drop the 'full match' off the front and leave the captures
    matches = matches.to_a.drop(1)

    proc.call(*matches)
  elsif @argv =~ regexp
    proc.call
  end
end

#notify(type, msg = "#{Etc.getlogin} ran: #{@argv}") ⇒ Object



33
34
35
# File 'lib/knife_santoku/callback.rb', line 33

def notify(type, msg="#{Etc.getlogin} ran: #{@argv}")
  @notifier.notify(type, msg)
end

#runObject



15
16
17
# File 'lib/knife_santoku/callback.rb', line 15

def run
  from_file(@file)
end