Sha256: 9afd0f55159e8826963c397846f4a8e814d8bfb572fa2d2490d3e4c4bb310ea6

Contents?: true

Size: 728 Bytes

Versions: 4

Compression:

Stored size: 728 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}".color(: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

4 entries across 4 versions & 1 rubygems

Version Path
forger-3.0.2 lib/forger/hook.rb
forger-3.0.1 lib/forger/hook.rb
forger-3.0.0 lib/forger/hook.rb
forger-2.0.5 lib/forger/hook.rb