Sha256: 842c07019fbb426ca8f09467303d845def90ed122ffbc9c4406869438bc02c92

Contents?: true

Size: 730 Bytes

Versions: 26

Compression:

Stored size: 730 Bytes

Contents

require 'yaml'

module AwsEc2
  class Hook
    def initialize(options={})
      @options = options
    end

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

    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

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

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

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
aws-ec2-1.4.9 lib/aws_ec2/hook.rb
aws-ec2-1.4.8 lib/aws_ec2/hook.rb
aws-ec2-1.4.7 lib/aws_ec2/hook.rb
aws-ec2-1.4.6 lib/aws_ec2/hook.rb
aws-ec2-1.4.5 lib/aws_ec2/hook.rb
aws-ec2-1.4.4 lib/aws_ec2/hook.rb
aws-ec2-1.4.3 lib/aws_ec2/hook.rb
aws-ec2-1.4.2 lib/aws_ec2/hook.rb
aws-ec2-1.4.1 lib/aws_ec2/hook.rb
aws-ec2-1.4.0 lib/aws_ec2/hook.rb
aws-ec2-1.3.2 lib/aws_ec2/hook.rb
aws-ec2-1.3.1 lib/aws_ec2/hook.rb
aws-ec2-1.3.0 lib/aws_ec2/hook.rb
aws-ec2-1.2.2 lib/aws_ec2/hook.rb
aws-ec2-1.2.1 lib/aws_ec2/hook.rb
aws-ec2-1.2.0 lib/aws_ec2/hook.rb
aws-ec2-1.1.0 lib/aws_ec2/hook.rb
aws-ec2-1.0.0 lib/aws_ec2/hook.rb
aws-ec2-0.9.0 lib/aws_ec2/hook.rb
aws-ec2-0.8.4 lib/aws_ec2/hook.rb