class Inprovise::LocalFile

Attributes

path[R]

Public Class Methods

new(context, path) click to toggle source
# File lib/inprovise/local_file.rb, line 13
def initialize(context, path)
  @context = context
  @path = resolve(path)
end

Public Instance Methods

content() click to toggle source
# File lib/inprovise/local_file.rb, line 43
def content
  return File.read(@path) if exists?
  nil
end
copy_from(source) click to toggle source
# File lib/inprovise/local_file.rb, line 72
def copy_from(source)
  source = self.class.new(source) if String === source
  source.copy_to(self)
end
copy_to(destination) click to toggle source
# File lib/inprovise/local_file.rb, line 53
def copy_to(destination)
  destination = self.class.new(destination) if String === destination
  if destination.is_local?
    duplicate(destination)
  else
    upload(destination)
  end
end
delete!() click to toggle source
# File lib/inprovise/local_file.rb, line 103
def delete!
  FileUtils.rm(path) if exists?
  self
end
directory?() click to toggle source
# File lib/inprovise/local_file.rb, line 35
def directory?
  File.directory?(path)
end
download(source) click to toggle source
# File lib/inprovise/local_file.rb, line 93
def download(source)
  source = @context.remote(source) if String === source
  if source.is_local?
    FileUtils.cp(source.path, path)
  else
    source.download(self)
  end
  self
end
duplicate(destination) click to toggle source
# File lib/inprovise/local_file.rb, line 77
def duplicate(destination)
  destination = self.class.new(destination) if String === destination
  FileUtils.cp(path, destination.path)
  destination
end
exists?() click to toggle source
# File lib/inprovise/local_file.rb, line 31
def exists?
  File.exists?(@path)
end
file?() click to toggle source
# File lib/inprovise/local_file.rb, line 39
def file?
  File.file?(path)
end
group() click to toggle source
# File lib/inprovise/local_file.rb, line 126
def group
  Etc.getgrgid(File.stat(path).gid).name
end
hash() click to toggle source
# File lib/inprovise/local_file.rb, line 26
def hash
  return nil unless exists?
  Digest::SHA1.file(path).hexdigest
end
is_local?() click to toggle source
# File lib/inprovise/local_file.rb, line 130
def is_local?
  true
end
matches?(other) click to toggle source

deosnt check permissions or user. should it?

# File lib/inprovise/local_file.rb, line 49
def matches?(other)
  self.exists? && other.exists? && self.hash == other.hash
end
move_to(destination) click to toggle source
# File lib/inprovise/local_file.rb, line 62
def move_to(destination)
  destination = self.class.new(destination) if String === destination
  if destination.is_local?
    FileUtils.mv(path, destination.path)
  else
    upload(destination)
  end
  destination
end
permissions() click to toggle source
# File lib/inprovise/local_file.rb, line 113
def permissions
   File.stat(path).mode & 0777
end
resolve(path) click to toggle source
# File lib/inprovise/local_file.rb, line 18
def resolve(path)
  if path =~ /^\//
    path
  else
    File.join(Inprovise.root, path)
  end
end
set_owner(user, group=nil) click to toggle source
# File lib/inprovise/local_file.rb, line 117
def set_owner(user, group=nil)
  FileUtils.chown_R(user, group, path)
  self
end
set_permissions(mask) click to toggle source
# File lib/inprovise/local_file.rb, line 108
def set_permissions(mask)
  FileUtils.chmod_R(mask, path)
  self
end
upload(destination) click to toggle source
# File lib/inprovise/local_file.rb, line 83
def upload(destination)
  destination = @context.remote(destination) if String === destination
  if destination.is_local?
    duplicate(destination)
  else
    destination.upload(self)
  end
  destination
end
user() click to toggle source
# File lib/inprovise/local_file.rb, line 122
def user
  Etc.getpwuid(File.stat(path).uid).name
end