Class: Orca::LocalFile

Inherits:
Object
  • Object
show all
Defined in:
lib/orca/local_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ LocalFile

Returns a new instance of LocalFile.



7
8
9
# File 'lib/orca/local_file.rb', line 7

def initialize(path)
  @path = resolve(path)
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'lib/orca/local_file.rb', line 5

def path
  @path
end

Instance Method Details

#copy_from(destination) ⇒ Object



42
43
44
# File 'lib/orca/local_file.rb', line 42

def copy_from(destination)
  destination.copy_to(self)
end

#copy_to(destination) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/orca/local_file.rb', line 33

def copy_to(destination)
  if destination.is_local?
    duplicate(destination)
  else
    upload(destination)
  end
  destination
end

#delete!Object



55
56
57
58
# File 'lib/orca/local_file.rb', line 55

def delete!
  FileUtils.rm(path) if exists?
  self
end

#duplicate(destination) ⇒ Object



46
47
48
49
# File 'lib/orca/local_file.rb', line 46

def duplicate(destination)
  FileUtils.cp(path, destination.path)
  destination
end

#exists?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/orca/local_file.rb', line 24

def exists?
  File.exists?(@path)
end

#hashObject



19
20
21
22
# File 'lib/orca/local_file.rb', line 19

def hash
  return nil unless exists?
  Digest::SHA1.file(path).hexdigest
end

#is_local?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/orca/local_file.rb', line 74

def is_local?
  true
end

#matches?(other) ⇒ Boolean

deosnt check permissions or user. should it?

Returns:

  • (Boolean)


29
30
31
# File 'lib/orca/local_file.rb', line 29

def matches?(other)
  self.exists? && other.exists? && self.hash == other.hash
end

#permissionsObject



65
66
67
# File 'lib/orca/local_file.rb', line 65

def permissions
   File.stat(path).mode & 0777
end

#resolve(path) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/orca/local_file.rb', line 11

def resolve(path)
  if path =~ /^\//
    path
  else
    File.join(Orca.root, path)
  end
end

#set_owner(user, group = nil) ⇒ Object



69
70
71
72
# File 'lib/orca/local_file.rb', line 69

def set_owner(user, group=nil)
  FileUtils.chown_R(user, group, path)
  self
end

#set_permissions(mask) ⇒ Object



60
61
62
63
# File 'lib/orca/local_file.rb', line 60

def set_permissions(mask)
  FileUtils.chmod_R(mask, path)
  self
end

#upload(destination) ⇒ Object



51
52
53
# File 'lib/orca/local_file.rb', line 51

def upload(destination)
  destination.upload(self)
end