Class: Orca::LocalFile
- Inherits:
-
Object
- Object
- Orca::LocalFile
- Defined in:
- lib/orca/local_file.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #copy_from(destination) ⇒ Object
- #copy_to(destination) ⇒ Object
- #delete! ⇒ Object
- #duplicate(destination) ⇒ Object
- #exists? ⇒ Boolean
- #hash ⇒ Object
-
#initialize(path) ⇒ LocalFile
constructor
A new instance of LocalFile.
- #is_local? ⇒ Boolean
-
#matches?(other) ⇒ Boolean
deosnt check permissions or user.
- #permissions ⇒ Object
- #resolve(path) ⇒ Object
- #set_owner(user, group = nil) ⇒ Object
- #set_permissions(mask) ⇒ Object
- #upload(destination) ⇒ Object
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
#path ⇒ Object (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
24 25 26 |
# File 'lib/orca/local_file.rb', line 24 def exists? File.exists?(@path) end |
#hash ⇒ Object
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
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?
29 30 31 |
# File 'lib/orca/local_file.rb', line 29 def matches?(other) self.exists? && other.exists? && self.hash == other.hash end |
#permissions ⇒ Object
65 66 67 |
# File 'lib/orca/local_file.rb', line 65 def 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 (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 |