Sha256: f60aecba94551292ca60299d39e95c2bb14e921404c7b693c92d914ffe71013a

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

module Mina
  class Commands
    extend Forwardable
    include Helpers::Internal
    include Configuration::DSL

    attr_reader :queue
    attr_accessor :stage

    def initialize(stage = :default)
      @stage = stage
      @queue = Hash.new { |hash, key| hash[key] = [] }
    end

    def command(code, quiet: false, indent: nil)
      code = indent(indent, code) if indent
      queue[stage] << (quiet ? code : echo_cmd(code))
    end

    def comment(code, indent: nil)
      if indent
        queue[stage] << indent(indent, %(echo "-----> #{code}"))
      else
        queue[stage] << %(echo "-----> #{code}")
      end
    end

    def delete(stage)
      queue.delete(stage) || []
    end

    def process(path = nil)
      if path
        queue[stage].unshift(%(echo "$ cd #{path}")) if fetch(:verbose)
        %((cd #{path} && #{queue[stage].join(' && ')}))
      else
        queue[stage].join("\n")
      end
    end

    def run(backend)
      report_time do
        status = Mina::Runner.new(process, backend).run
        error! 'Run Error' unless status
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mina-1.0.0.beta3 lib/mina/commands.rb