class Inprovise::RemoteFile

Attributes

path[R]

Public Class Methods

new(context, path) click to toggle source
# File lib/inprovise/remote_file.rb, line 12
def initialize(context, path)
  @context = context
  @path = path
  @exists = nil
  @permissions = nil
  @owner = nil
end

Public Instance Methods

content() click to toggle source
# File lib/inprovise/remote_file.rb, line 38
def content
  @context.node.cat(path)
end
copy_from(source) click to toggle source
# File lib/inprovise/remote_file.rb, line 66
def copy_from(source)
  source = @context.remote(source) if String === source
  source.copy_to(self)
end
copy_to(destination) click to toggle source
# File lib/inprovise/remote_file.rb, line 47
def copy_to(destination)
  destination = @context.remote(destination) if String === destination
  if destination.is_local?
    download(destination)
  else
    duplicate(destination)
  end
end
delete!() click to toggle source
# File lib/inprovise/remote_file.rb, line 97
def delete!
  @context.remove(path) if exists?
  invalidate!
  self
end
directory?() click to toggle source
# File lib/inprovise/remote_file.rb, line 30
def directory?
  @context.node.directory?(path)
end
download(destination) click to toggle source
# File lib/inprovise/remote_file.rb, line 77
def download(destination)
  destination = @context.local(destination) if String === destination
  if destination.is_local?
    @context.download(path, destination.path)
  else
    @context.copy(path, destination.path)
  end
  destination
end
duplicate(destination) click to toggle source
# File lib/inprovise/remote_file.rb, line 71
def duplicate(destination)
  destination = @context.remote(destination) if String === destination
  @context.copy(path, destination.path)
  destination
end
exists?() click to toggle source
# File lib/inprovise/remote_file.rb, line 25
def exists?
  return @exists unless @exists.nil?
  @exists = @context.node.exists?(path)
end
file?() click to toggle source
# File lib/inprovise/remote_file.rb, line 34
def file?
  @context.node.file?(path)
end
group() click to toggle source
# File lib/inprovise/remote_file.rb, line 128
def group
  owner[:group]
end
hash() click to toggle source
# File lib/inprovise/remote_file.rb, line 20
def hash
  return nil unless exists?
  @hash ||= @context.node.hash_for(path)
end
is_local?() click to toggle source
# File lib/inprovise/remote_file.rb, line 132
def is_local?
  false
end
matches?(other) click to toggle source

doesnt check permissions or user. should it?

# File lib/inprovise/remote_file.rb, line 43
def matches?(other)
  self.exists? && other.exists? && self.hash == other.hash
end
move_to(destination) click to toggle source
# File lib/inprovise/remote_file.rb, line 56
def move_to(destination)
  destination = @context.remote(destination) if String === destination
  if destination.is_local?
    download(destination)
  else
    @context.move(path, destination.path)
  end
  destination
end
owner() click to toggle source
# File lib/inprovise/remote_file.rb, line 120
def owner
  @owner ||= @context.node.owner(path)
end
permissions() click to toggle source
# File lib/inprovise/remote_file.rb, line 109
def permissions
  @permissions ||= @context.node.permissions(path)
end
set_owner(user, group=nil) click to toggle source
# File lib/inprovise/remote_file.rb, line 113
def set_owner(user, group=nil)
  user ||= owner[:user]
  @context.set_owner(path, user, group)
  invalidate!
  self
end
set_permissions(mask) click to toggle source
# File lib/inprovise/remote_file.rb, line 103
def set_permissions(mask)
  @context.set_permissions(path, mask)
  invalidate!
  self
end
upload(source) click to toggle source
# File lib/inprovise/remote_file.rb, line 87
def upload(source)
  source = @context.local(source) if String === source
  if source.is_local?
    @context.upload(source.path, path)
  else
    @context.copy(source.path, path)
  end
  self
end
user() click to toggle source
# File lib/inprovise/remote_file.rb, line 124
def user
  owner[:user]
end

Private Instance Methods

invalidate!() click to toggle source
# File lib/inprovise/remote_file.rb, line 138
def invalidate!
  @permissions = nil
  @owner = nil
end