Sha256: 9632afc5b5e49ed7a8ba3ecc08cf234973eee9e7b5a76d28c7ee330ac7dde861

Contents?: true

Size: 747 Bytes

Versions: 1

Compression:

Stored size: 747 Bytes

Contents

class SourceTreeSyncer
  attr_accessor :exclude
  attr_reader :sys_command

  SYS_COMMAND = 'rsync'
  OPTS = '-az'
  EXCLUDE_OPT = "--exclude"

  def initialize source_tree_path
    @source_tree_path = source_tree_path
    @exclude = []
  end

  def sync
    @tempdir = Dir.mktmpdir("gorgon")
    Dir.chdir(@tempdir)

    exclude_opt = build_exclude_opt
    @sys_command = "#{SYS_COMMAND} #{OPTS} #{exclude_opt} -r --rsh=ssh #{@source_tree_path}/* ."
    system(@sys_command)

    return $?.exitstatus == 0
  end

  def remove_temp_dir
    FileUtils::remove_entry_secure(@tempdir)
  end

  private

  def build_exclude_opt
    return "" if @exclude.nil? or @exclude.empty?

    @exclude.unshift("")
    @exclude.join(" #{EXCLUDE_OPT} ")
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gorgon-0.0.1 lib/gorgon/source_tree_syncer.rb