Class: CloudFS::FileSystem
- Inherits:
-
Object
- Object
- CloudFS::FileSystem
- Defined in:
- lib/cloudfs/filesystem.rb
Overview
FileSystem class provides interface to maintain cloudfs user's filesystem
Instance Method Summary collapse
-
#create_share(paths, password: nil) ⇒ Share
Create share of paths in user's filesystem.
-
#get_item(path) ⇒ Object
Get an item located in a given location.
-
#initialize(rest_adapter) ⇒ FileSystem
constructor
A new instance of FileSystem.
-
#list_shares ⇒ Array<Share>
List shares created by end-user RestAdapter::Errors::ServiceError].
-
#list_trash ⇒ Array<File, Folder>
Items in trash.
-
#retrieve_share(share_key, password: nil) ⇒ Share
Fetches share associated with share key.
-
#root ⇒ Folder
Get root object of filesystem.
Constructor Details
#initialize(rest_adapter) ⇒ FileSystem
Returns a new instance of FileSystem.
25 26 27 28 29 |
# File 'lib/cloudfs/filesystem.rb', line 25
def initialize(rest_adapter)
fail RestAdapter::Errors::ArgumentError,
'invalid RestAdapter, input type must be RestAdapter' unless rest_adapter.is_a?(RestAdapter)
@rest_adapter = rest_adapter
end
|
Instance Method Details
#create_share(paths, password: nil) ⇒ Share
Create share of paths in user's filesystem
65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/cloudfs/filesystem.rb', line 65
def create_share(paths, password: nil)
fail RestAdapter::Errors::ArgumentError,
'Invalid input, expected items or paths' unless paths
path_list = []
[*paths].each do |path|
FileSystemCommon.validate_item_state(path)
path_list << FileSystemCommon.get_item_url(path)
end
response = @rest_adapter.create_share(path_list, password: password)
FileSystemCommon.create_item_from_hash(@rest_adapter, ** response)
end
|
#get_item(path) ⇒ Object
Get an item located in a given location.
99 100 101 102 103 104 105 106 107 108 |
# File 'lib/cloudfs/filesystem.rb', line 99
def get_item(path)
fail RestAdapter::Errors::ArgumentError,
'Invalid input, expected item path' if RestAdapter::Utils.is_blank?(path)
if path.is_a?(String)
FileSystemCommon.get_item(@rest_adapter, path)
else
nil
end
end
|
#list_shares ⇒ Array<Share>
List shares created by end-user RestAdapter::Errors::ServiceError]
49 50 51 52 |
# File 'lib/cloudfs/filesystem.rb', line 49
def list_shares
response = @rest_adapter.list_shares
FileSystemCommon.create_items_from_hash_array(response, @rest_adapter)
end
|
#list_trash ⇒ Array<File, Folder>
Returns items in trash.
36 37 38 39 40 41 42 |
# File 'lib/cloudfs/filesystem.rb', line 36
def list_trash
response = @rest_adapter.browse_trash.fetch(:items)
FileSystemCommon.create_items_from_hash_array(
response,
@rest_adapter,
in_trash: true)
end
|
#retrieve_share(share_key, password: nil) ⇒ Share
Note:
This method is intended for retrieving share from another user
Fetches share associated with share key.
89 90 91 92 93 94 95 96 |
# File 'lib/cloudfs/filesystem.rb', line 89
def retrieve_share(share_key, password: nil)
fail RestAdapter::Errors::ArgumentError,
'Invalid input, expected items or paths' if RestAdapter::Utils.is_blank?(share_key)
@rest_adapter.unlock_share(share_key, password) if password
response = @rest_adapter.browse_share(share_key).fetch(:share)
FileSystemCommon.create_item_from_hash(@rest_adapter, ** response)
end
|
#root ⇒ Folder
Get root object of filesystem
17 18 19 20 |
# File 'lib/cloudfs/filesystem.rb', line 17
def root
response = @rest_adapter.get_folder_meta('/')
FileSystemCommon.create_item_from_hash(@rest_adapter, ** response)
end
|