Sha256: ae9bd6f36e90e9138680cb0a54c92fc22af732690f03aa748b2cb45ac1a7f7ec

Contents?: true

Size: 731 Bytes

Versions: 5

Compression:

Stored size: 731 Bytes

Contents

require 'yaml'

module Forger
  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 = "#{Forger.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(:green)
      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

5 entries across 5 versions & 1 rubygems

Version Path
forger-2.0.4 lib/forger/hook.rb
forger-2.0.3 lib/forger/hook.rb
forger-2.0.2 lib/forger/hook.rb
forger-2.0.1 lib/forger/hook.rb
forger-2.0.0 lib/forger/hook.rb