Sha256: 18adb265e54e8a2489072e27027b5aabfaa2a52e0f856446e44c5530f7336887

Contents?: true

Size: 1.29 KB

Versions: 1

Compression:

Stored size: 1.29 KB

Contents

require "scripted/commands/shell"
require "scripted/commands/rake"
require "scripted/commands/ruby"

module Scripted
  class Command

    attr_reader :name

    def initialize(name, options = {}, &block)
      @name = name
      @options = options
      define(&block) if block
    end

    def define(&block)
      instance_eval &block
    end

    def executable
      @command || Commands::Shell.new(@name)
    end

    def execute!(logger)
      executable.execute!(logger)
    end

    def sh(command)
      @command = Commands::Shell.new(command)
    end
    alias_method :`, :sh

    def rake(command)
      @command = Commands::Rake.new(command)
    end

    def ruby(&code)
      @command = Commands::Ruby.new(code)
    end

    def important!
      @important = true
    end

    def important?
      !!@important
    end

    def unimportant?
      !!@unimportant
    end

    def unimportant!
      @unimportant = true
    end

    def forced!
      @forced = true
    end

    def forced?
      !!@forced
    end

    def parallel_id
      @options[:parallel_id]
    end

    def run_in_parallel_with?(other)
      other && parallel_id == other.parallel_id
    end

    def only_when_failed?
      !!@only_when_failed
    end

    def only_when_failed!
      @only_when_failed = true
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
scripted-0.0.1 lib/scripted/command.rb