Class: AwsEc2::Hook

Inherits:
Object
  • Object
show all
Defined in:
lib/aws_ec2/hook.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Hook

Returns a new instance of Hook.



5
6
7
# File 'lib/aws_ec2/hook.rb', line 5

def initialize(options={})
  @options = options
end

Class Method Details

.run(name, options = {}) ⇒ Object



29
30
31
# File 'lib/aws_ec2/hook.rb', line 29

def self.run(name, options={})
  Hook.new(options).run(name.to_s)
end

Instance Method Details

#hooksObject



17
18
19
20
21
# File 'lib/aws_ec2/hook.rb', line 17

def hooks
  hooks_path = "#{AwsEc2.root}/config/hooks.yml"
  data = File.exist?(hooks_path) ? YAML.load_file(hooks_path) : {}
  data ? data : {} # in case the file is empty
end

#run(name) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/aws_ec2/hook.rb', line 9

def run(name)
  return if @options[:noop]
  return unless hooks[name]
  command = hooks[name]
  puts "Running hook #{name}: #{command}"
  sh(command)
end

#sh(command) ⇒ Object



23
24
25
26
27
# File 'lib/aws_ec2/hook.rb', line 23

def sh(command)
  puts "=> #{command}".colorize(:cyan)
  success = system(command)
  abort("Command failed") unless success
end