Sha256: e6cf23518d6df253c7de119a014dbd1f23f7e81852c2665e08231f5f8ff52e48

Contents?: true

Size: 1.6 KB

Versions: 10

Compression:

Stored size: 1.6 KB

Contents

require 'pathname'
require 'engineyard-serverside/spawner'
require 'escape'

class EY::Serverside::Source
  attr_reader :uri, :opts, :source_cache, :ref, :shell
  alias repository_cache source_cache

  class << self
    attr_reader :required_opts
    def require_opts(*names)
      @required_opts ||= []
      @required_opts += names
    end

    def for(type)
      const_get(type)
    end
  end

  def initialize(shell, opts={})
    @shell = shell
    @opts = opts

    if self.class.required_opts && !self.class.required_opts.all? {|name| @opts[name] }
      raise ArgumentError,
        "Missing required key(s) (#{self.class.required_opts.join(', ')} required)"
    end

    @ref = @opts[:ref]
    @uri = @opts[:uri].to_s if @opts[:uri]
    @source_cache = Pathname.new(@opts[:repository_cache]) if @opts[:repository_cache]
  end

  protected

  def in_source_cache(&block)
    raise ArgumentError, "Block required" unless block
    source_cache.mkpath
    Dir.chdir(source_cache, &block)
  end

  def escape(*shell_commands)
    Escape.shell_command(shell_commands)
  end

  def runner
    EY::Serverside::Spawner
  end

  # Internal: Run a command.
  #
  # cmd - A string command.
  #
  # Returns an instance of Spawner.
  def run(cmd)
    runner.run(cmd, shell, nil)
  end

  # Internal: Run a command and return the output.
  #
  # cmd - A string command.
  #
  # Returns the output of the command.
  def run_and_output(cmd)
    run(cmd).output
  end

  # Internal: Run a command and check if it was successful.
  #
  # cmd - A string command.
  #
  # Returns success.
  def run_and_success?(cmd)
    run(cmd).success?
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
engineyard-serverside-2.3.9 lib/engineyard-serverside/source_strategy.rb
engineyard-serverside-2.3.7 lib/engineyard-serverside/source_strategy.rb
engineyard-serverside-2.3.6 lib/engineyard-serverside/source_strategy.rb
engineyard-serverside-2.3.5 lib/engineyard-serverside/source_strategy.rb
engineyard-serverside-2.3.4 lib/engineyard-serverside/source_strategy.rb
engineyard-serverside-2.3.3 lib/engineyard-serverside/source_strategy.rb
engineyard-serverside-2.3.2 lib/engineyard-serverside/source_strategy.rb
engineyard-serverside-2.3.1 lib/engineyard-serverside/source_strategy.rb
engineyard-serverside-2.3.1.pre.archivefix lib/engineyard-serverside/source_strategy.rb
engineyard-serverside-2.3.0 lib/engineyard-serverside/source_strategy.rb