Class: Hooks::Command

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

Defined Under Namespace

Classes: NoHookError

Class Method Summary collapse

Class Method Details

.execute(commands, options = {}) ⇒ Object

options include the directory to execute the command (that’s it for now, will add more functionality later)



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/hooks/executer.rb', line 8

def self.execute(commands, options={})
  opts = {:directory => nil, :repo => nil}.merge(options)
  dir  = opts[:directory]
  repo = opts[:repo]
  begin

  commands.each do |cmd|
    if dir
      Dir.chdir(File.expand_path(dir)) do
        ::Kernel.system cmd
      end
    else
      ::Kernel.system cmd
    end
  end

  rescue ArgumentError
    raise NoHookError.new "There aren't any hook commands for the repository #{repo}"
  end
end