Sha256: a2a3b221e33c4f6d46f1786842cbc846f7480c90020d86e548defaeccd8bcb17

Contents?: true

Size: 966 Bytes

Versions: 14

Compression:

Stored size: 966 Bytes

Contents

module Ufo::Hooks
  class Runner
    include Ufo::Utils::Logging
    include Ufo::Utils::Execute

    attr_reader :hook
    def initialize(hook)
      @hook = hook
      @execute = @hook["execute"]
    end

    def run
      case @execute
      when String
        execute(@execute, exit_on_fail: @hook["exit_on_fail"])
      when -> (e) { e.respond_to?(:public_instance_methods) && e.public_instance_methods.include?(:call) }
        executor = @execute.new
      when -> (e) { e.respond_to?(:call) }
        executor = @execute
      else
        logger.warn "WARN: execute option not set for hook: #{@hook.inspect}"
      end

      return unless executor

      meth = executor.method(:call)
      case meth.arity
      when 0
        executor.call # backwards compatibility
      when 1
        executor.call(self)
      else
        raise "The #{executor} call method definition has been more than 1 arguments and is not supported"
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
ufo-6.3.13 lib/ufo/hooks/runner.rb
ufo-6.3.12 lib/ufo/hooks/runner.rb
ufo-6.3.11 lib/ufo/hooks/runner.rb
ufo-6.3.10 lib/ufo/hooks/runner.rb
ufo-6.3.9 lib/ufo/hooks/runner.rb
ufo-6.3.8 lib/ufo/hooks/runner.rb
ufo-6.3.7 lib/ufo/hooks/runner.rb
ufo-6.3.6 lib/ufo/hooks/runner.rb
ufo-6.3.5 lib/ufo/hooks/runner.rb
ufo-6.3.4 lib/ufo/hooks/runner.rb
ufo-6.3.3 lib/ufo/hooks/runner.rb
ufo-6.3.2 lib/ufo/hooks/runner.rb
ufo-6.3.1 lib/ufo/hooks/runner.rb
ufo-6.3.0 lib/ufo/hooks/runner.rb