Class: CloudFS::Folder
- Defined in:
- lib/cloudfs/folder.rb
Overview
Represents a folder in the user's filesystem that can contain files and other folders.
Instance Attribute Summary
Attributes inherited from Item
#blocklist_id, #blocklist_key, #date_content_last_modified, #date_created, #date_meta_last_modified, #id, #is_mirrored, #name, #parent_id, #type, #url, #version
Instance Method Summary collapse
-
#create_folder(name, exists: 'FAIL') ⇒ Folder
Create folder under this container.
-
#upload(file_system_path, name: nil, exists: 'FAIL', upload_io: false) ⇒ File
Upload file to this folder.
Methods inherited from Container
Methods inherited from Item
#application_data, #application_data=, #change_attributes, #copy, #delete, #exists?, #in_share?, #in_trash?, #initialize, #move, #old_version?, #path, #refresh, #restore, #save, #versions
Constructor Details
This class inherits a constructor from CloudFS::Container
Instance Method Details
#create_folder(name, exists: 'FAIL') ⇒ Folder
Create folder under this container
75 76 77 78 79 80 81 82 |
# File 'lib/cloudfs/folder.rb', line 75
def create_folder(name, exists: 'FAIL')
FileSystemCommon.validate_item_state(self)
fail RestAdapter::Errors::ArgumentError,
'Invalid argument, must pass name' if RestAdapter::Utils.is_blank?(name)
properties = @rest_adapter.create_folder(name, path: @url, exists: exists)
FileSystemCommon.create_item_from_hash(@rest_adapter, parent: @url, ** properties)
end
|
#upload(file_system_path, name: nil, exists: 'FAIL', upload_io: false) ⇒ File
Upload file to this folder
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/cloudfs/folder.rb', line 49
def upload(file_system_path, name: nil, exists: 'FAIL', upload_io: false)
FileSystemCommon.validate_item_state(self)
fail RestAdapter::Errors::ArgumentError,
'Invalid input, expected file system path.' if RestAdapter::Utils.is_blank?(file_system_path)
if upload_io == false
response = ::File.open(file_system_path, 'r') do |file|
@rest_adapter.upload(@url, file, name: name, exists: exists)
end
else
response = @rest_adapter.upload(@url, file_system_path, name: name, exists: exists)
end
FileSystemCommon.create_item_from_hash(@rest_adapter,
parent: @url, ** response)
end
|