Class: Inprovise::RemoteFile
- Inherits:
-
Object
- Object
- Inprovise::RemoteFile
- Defined in:
- lib/inprovise/remote_file.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #content ⇒ Object
- #copy_from(destination) ⇒ Object
- #copy_to(destination) ⇒ Object
- #delete! ⇒ Object
- #directory? ⇒ Boolean
- #download(destination) ⇒ Object
- #duplicate(destination) ⇒ Object
- #exists? ⇒ Boolean
- #file? ⇒ Boolean
- #group ⇒ Object
- #hash ⇒ Object
-
#initialize(context, path) ⇒ RemoteFile
constructor
A new instance of RemoteFile.
- #is_local? ⇒ Boolean
-
#matches?(other) ⇒ Boolean
doesnt check permissions or user.
- #owner ⇒ Object
- #permissions ⇒ Object
- #set_owner(user, group = nil) ⇒ Object
- #set_permissions(mask) ⇒ Object
- #upload(source) ⇒ Object
- #user ⇒ Object
Constructor Details
#initialize(context, path) ⇒ RemoteFile
Returns a new instance of RemoteFile.
12 13 14 15 16 17 18 |
# File 'lib/inprovise/remote_file.rb', line 12 def initialize(context, path) @context = context @path = path @exists = nil @permissions = nil @owner = nil end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
10 11 12 |
# File 'lib/inprovise/remote_file.rb', line 10 def path @path end |
Instance Method Details
#content ⇒ Object
38 39 40 |
# File 'lib/inprovise/remote_file.rb', line 38 def content @context.node.cat(path) end |
#copy_from(destination) ⇒ Object
56 57 58 |
# File 'lib/inprovise/remote_file.rb', line 56 def copy_from(destination) destination.copy_to(self) end |
#copy_to(destination) ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/inprovise/remote_file.rb', line 47 def copy_to(destination) if destination.is_local? download(destination) else duplicate(destination) end destination end |
#delete! ⇒ Object
83 84 85 86 87 |
# File 'lib/inprovise/remote_file.rb', line 83 def delete! @context.remove(path) if exists? invalidate! self end |
#directory? ⇒ Boolean
30 31 32 |
# File 'lib/inprovise/remote_file.rb', line 30 def directory? @context.node.directory?(path) end |
#download(destination) ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'lib/inprovise/remote_file.rb', line 65 def download(destination) if String === destination || destination.is_local? @context.download(path, String === destination ? destination : destination.path) else @context.copy(path, destination.path) end String === destination ? @context.local(destination) : destination end |
#duplicate(destination) ⇒ Object
60 61 62 63 |
# File 'lib/inprovise/remote_file.rb', line 60 def duplicate(destination) @context.copy(path, destination.path) destination end |
#exists? ⇒ Boolean
25 26 27 28 |
# File 'lib/inprovise/remote_file.rb', line 25 def exists? return @exists unless @exists.nil? @exists = @context.node.exists?(path) end |
#file? ⇒ Boolean
34 35 36 |
# File 'lib/inprovise/remote_file.rb', line 34 def file? @context.node.file?(path) end |
#group ⇒ Object
114 115 116 |
# File 'lib/inprovise/remote_file.rb', line 114 def group owner[:group] end |
#hash ⇒ Object
20 21 22 23 |
# File 'lib/inprovise/remote_file.rb', line 20 def hash return nil unless exists? @hash ||= @context.node.hash_for(path) end |
#is_local? ⇒ Boolean
118 119 120 |
# File 'lib/inprovise/remote_file.rb', line 118 def is_local? false end |
#matches?(other) ⇒ Boolean
doesnt check permissions or user. should it?
43 44 45 |
# File 'lib/inprovise/remote_file.rb', line 43 def matches?(other) self.exists? && other.exists? && self.hash == other.hash end |
#owner ⇒ Object
106 107 108 |
# File 'lib/inprovise/remote_file.rb', line 106 def owner @owner ||= @context.node.owner(path) end |
#permissions ⇒ Object
95 96 97 |
# File 'lib/inprovise/remote_file.rb', line 95 def @permissions ||= @context.node.(path) end |
#set_owner(user, group = nil) ⇒ Object
99 100 101 102 103 104 |
# File 'lib/inprovise/remote_file.rb', line 99 def set_owner(user, group=nil) user ||= owner[:user] @context.set_owner(path, user, group) invalidate! self end |
#set_permissions(mask) ⇒ Object
89 90 91 92 93 |
# File 'lib/inprovise/remote_file.rb', line 89 def (mask) @context.(path, mask) invalidate! self end |
#upload(source) ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'lib/inprovise/remote_file.rb', line 74 def upload(source) if String === source || source.is_local? @context.upload(String === source ? source : source.path, path) else @context.copy(source.path, path) end self end |
#user ⇒ Object
110 111 112 |
# File 'lib/inprovise/remote_file.rb', line 110 def user owner[:user] end |