Sha256: a72ce3bd40d548edacb65d42db9ed415488ee9a3d55323a8489a415f01e1bdc7

Contents?: true

Size: 1.58 KB

Versions: 4

Compression:

Stored size: 1.58 KB

Contents

module DeepTest
  module Distributed
    class RSync
      def self.push(address, sync_options, destination)
        sync(:push, address, sync_options, destination)
      end

      def self.sync(operation, address, sync_options, destination)
        command = Args.new(address, sync_options).send("#{operation}_command", 
                                                  destination)

        DeepTest.logger.debug { "rsycing: #{command}" }
        successful = system command
        raise "RSync Failed!!" unless successful
      end

      class Args
        def initialize(address, sync_options)
          @address = address
          @sync_options = sync_options
        end

        def pull_command(destination)
          command remote_location(@sync_options[:source]), destination
        end

        def push_command(destination)
          command @sync_options[:source], remote_location(destination)
        end

        def command(source, destination)
          # The '/' after source tells rsync to copy the contents
          # of source to destination, rather than the source directory
          # itself
          "rsync -az --delete #{@sync_options[:rsync_options]} #{DeepTest::LIB_ROOT} #{source} #{destination}".strip.squeeze(" ")
        end

        def remote_location(path)
          source = ""
          unless @sync_options[:local]
            source << @sync_options[:username] << '@' if @sync_options[:username]
            source << @address
            source << (@sync_options[:daemon] ? '::' : ':')
          end
          source << path
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
deep_test_pre-2.0 lib/deep_test/distributed/rsync.rb
jstorimer-deep-test-2.0.0 lib/deep_test/distributed/rsync.rb
jstorimer-deep-test-0.2.0 lib/deep_test/distributed/rsync.rb
jstorimer-deep-test-0.1.0 lib/deep_test/distributed/rsync.rb