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(source) ⇒ 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.
- #move_to(destination) ⇒ Object
- #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(source) ⇒ Object
66 67 68 69 |
# 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) ⇒ Object
47 48 49 50 51 52 53 54 |
# 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! ⇒ Object
97 98 99 100 101 |
# File 'lib/inprovise/remote_file.rb', line 97 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
77 78 79 80 81 82 83 84 85 |
# 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) ⇒ Object
71 72 73 74 75 |
# 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? ⇒ 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
128 129 130 |
# File 'lib/inprovise/remote_file.rb', line 128 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
132 133 134 |
# File 'lib/inprovise/remote_file.rb', line 132 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 |
#move_to(destination) ⇒ Object
56 57 58 59 60 61 62 63 64 |
# 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 ⇒ Object
120 121 122 |
# File 'lib/inprovise/remote_file.rb', line 120 def owner @owner ||= @context.node.owner(path) end |
#permissions ⇒ Object
109 110 111 |
# File 'lib/inprovise/remote_file.rb', line 109 def @permissions ||= @context.node.(path) end |
#set_owner(user, group = nil) ⇒ Object
113 114 115 116 117 118 |
# 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) ⇒ Object
103 104 105 106 107 |
# File 'lib/inprovise/remote_file.rb', line 103 def (mask) @context.(path, mask) invalidate! self end |
#upload(source) ⇒ Object
87 88 89 90 91 92 93 94 95 |
# 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 ⇒ Object
124 125 126 |
# File 'lib/inprovise/remote_file.rb', line 124 def user owner[:user] end |