Sha256: 8d7feddc2140e06da2b94f61ea8219854f2be8081671937811fb3d7bc939d831

Contents?: true

Size: 694 Bytes

Versions: 7

Compression:

Stored size: 694 Bytes

Contents

module RsyncCron
  class Host
    def self.factory(s)
      return new(path: s) unless s.index(":")
      remote, path = s.split(":")
      new(path: path, remote: remote)
    end

    def initialize(path:, remote: nil)
      @path = path
      @remote = remote
    end

    def to_s
      [remote, path].compact.join(":")
    end

    def exist?
      return FileTest.exist?(path) unless remote?
      %x[ssh #{remote} "test -e #{path}"]
      $?.exitstatus.zero?
    end

    private def path
      return @path if remote?
      File.expand_path(@path)
    end

    private def remote
      return unless remote?
      @remote
    end

    private def remote?
      @remote
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rsync_cron-1.1.2 lib/rsync_cron/host.rb
rsync_cron-1.1.1 lib/rsync_cron/host.rb
rsync_cron-1.1.0 lib/rsync_cron/host.rb
rsync_cron-1.0.8 lib/rsync_cron/host.rb
rsync_cron-1.0.7 lib/rsync_cron/host.rb
rsync_cron-1.0.6 lib/rsync_cron/host.rb
rsync_cron-1.0.5 lib/rsync_cron/host.rb