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.
81 82 83 84 85 86 87 88 89 |
# File 'lib/droom/folders.rb', line 81 def get_parent_folder pfh = self.class.class_variable_get(:"@@parent_folder_holder") if pfh && holder = send(pfh.to_sym) holder.folder else # otherwise we want a root folder like /Events Droom::Folder.find_or_create_by_slug_and_parent_id(self.class.to_s.titlecase.split('/').last.pluralize, nil) 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 |