Module: Droom::Folders::FolderedInstanceMethods
- Defined in:
- lib/droom/folders.rb
Instance Method Summary collapse
-
#add_document(attributes) ⇒ Object
Create a new document in our folder, with the supplied properties.
- #all_documents ⇒ Object
-
#folder_with_lazy_load ⇒ Object
Folders are lazy-created.
-
#get_parent_folder ⇒ Object
Here we refer to the class variable defined during ‘has_folder` configuration.
-
#receive_document(doc) ⇒ Object
Move an existing document into our folder.
Instance Method Details
#add_document(attributes) ⇒ Object
Create a new document in our folder, with the supplied properties.
93 94 95 |
# File 'lib/droom/folders.rb', line 93 def add_document(attributes) folder.documents.create(attributes) end |
#all_documents ⇒ Object
73 74 75 |
# File 'lib/droom/folders.rb', line 73 def all_documents Droom::Document.in_folders(folder.family) end |
#folder_with_lazy_load ⇒ Object
Folders are lazy-created. That is, when we need it, we make it. This is achieved by chaining the ‘:folder` association method and creating a folder if none exists. This method definition must occur after the association has been defined.
69 70 71 |
# File 'lib/droom/folders.rb', line 69 def folder_with_lazy_load folder_without_lazy_load || self.create_folder(:parent => get_parent_folder) end |
#get_parent_folder ⇒ Object
Here we refer to the class variable defined during ‘has_folder` configuration. If it exists, we will put our folder inside that of the named associate. The containing folder might be created as a side effect. if it looks like an association name, we ask the associate for a folder. Otherwise we’ll just use it as a name.
81 82 83 84 85 86 87 88 89 |
# File 'lib/droom/folders.rb', line 81 def get_parent_folder parent_folder_option = self.class.class_variable_get(:"@@parent_folder_holder") if parent_folder_option && respond_to?(parent_folder_option.to_sym) && folder_holder = send(parent_folder_option.to_sym) folder_holder.folder else slug = parent_folder_option || self.class.to_s.titlecase.split('/').last.pluralize Droom::Folder.where(:slug => slug, :parent_id => nil).first_or_create end end |
#receive_document(doc) ⇒ Object
Move an existing document into our folder.
99 100 101 |
# File 'lib/droom/folders.rb', line 99 def receive_document(doc) folder.documents << doc end |