Class: Megar::Folder
- Inherits:
-
Object
- Object
- Megar::Folder
- Includes:
- CatalogItem
- Defined in:
- lib/megar/catalog/folder.rb
Overview
Folder collection item
Instance Attribute Summary
Attributes included from CatalogItem
#id, #key, #name, #parent_folder_id, #payload, #session, #type
Instance Method Summary collapse
-
#create(attributes) ⇒ Object
Command: creates a new file given
attributes
which contains the following elements: body: the file body. -
#files ⇒ Object
Returns a collection of files contained within this folder.
-
#folders ⇒ Object
Returns a collection of folders contained within this folder.
-
#initialize(attributes = {}) ⇒ Folder
constructor
Override initialisation to set special-purpose names.
-
#name=(value) ⇒ Object
Name assignment with special-purpose name support.
Methods included from CatalogItem
#==, #[], #add, #attributes=, #collection, #default_parent_folder, #each, #find_all_by_parent_folder_id, #find_all_by_type, #find_by_id, #find_by_name, #find_by_type, #parent_folder, #reset!, #resource_class
Constructor Details
#initialize(attributes = {}) ⇒ Folder
Override initialisation to set special-purpose names
15 16 17 18 |
# File 'lib/megar/catalog/folder.rb', line 15 def initialize(attributes={}) super self.name = nil unless name end |
Instance Method Details
#create(attributes) ⇒ Object
Command: creates a new file given attributes
which contains the following elements:
body: the file body. May be a Pathname, File, or filename (String)
name: the file name to assign (optional if already available from the body object)
The file is stored in the parent folder (or root folder by defult)
37 38 39 40 41 |
# File 'lib/megar/catalog/folder.rb', line 37 def create(attributes) if uploader = self.uploader(attributes) uploader.post! end end |
#files ⇒ Object
Returns a collection of files contained within this folder
27 28 29 30 |
# File 'lib/megar/catalog/folder.rb', line 27 def files return unless session session.files.find_all_by_parent_folder_id(id) end |
#folders ⇒ Object
Returns a collection of folders contained within this folder
21 22 23 24 |
# File 'lib/megar/catalog/folder.rb', line 21 def folders return unless session session.folders.find_all_by_parent_folder_id(id) end |
#name=(value) ⇒ Object
Name assignment with special-purpose name support
6 7 8 9 10 11 12 |
# File 'lib/megar/catalog/folder.rb', line 6 def name=(value) @name = if "#{value}" != "" value elsif type.is_a?(Fixnum) ["Cloud Drive","Inbox","Trash Bin"][type-2] end end |