Module: Cms::Behaviors::Attaching::ClassMethods
- Defined in:
- lib/cms/behaviors/attaching.rb
Instance Method Summary collapse
-
#attachments_as_of_version(version_number, attachable) ⇒ Array<Cms::Attachment>
Find all attachments as of the given version for the specified block.
-
#definitions_for(name) ⇒ Object
Return all definitions for a given class.
-
#has_attachment(name, options = {}) ⇒ Object
Defines an single attachement with a given name.
-
#has_many_attachments(name, options = {}) ⇒ Object
Allows multiple attachments under a specific name.
Instance Method Details
#attachments_as_of_version(version_number, attachable) ⇒ Array<Cms::Attachment>
Find all attachments as of the given version for the specified block. Excludes attachments that were deleted as of a version.
198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/cms/behaviors/attaching.rb', line 198 def (version_number, attachable) found_versions = Cms::Attachment::Version.where(:attachable_id => attachable.id). where(:attachable_type => attachable.attachable_type). where(:attachable_version => version_number). order(:version).all = [] found_versions.each do |av| record = av.build_object_from_version << record end .delete_if { |value| value.deleted? } end |
#definitions_for(name) ⇒ Object
Return all definitions for a given class.
214 215 216 |
# File 'lib/cms/behaviors/attaching.rb', line 214 def definitions_for(name) Cms::Attachment.definitions[self.name][name] end |
#has_attachment(name, options = {}) ⇒ Object
Defines an single attachement with a given name.
161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/cms/behaviors/attaching.rb', line 161 def (name, = {}) [:type] = :single [:index] = Cms::Attachment.definitions[self.name].size Cms::Attachment.definitions[self.name][name] = define_method name do (name) end define_method "#{name}?" do ((name) != nil) end end |
#has_many_attachments(name, options = {}) ⇒ Object
Allows multiple attachments under a specific name.
179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/cms/behaviors/attaching.rb', line 179 def (name, = {}) [:type] = :multiple Cms::Attachment.definitions[self.name][name] = define_method name do .named name end define_method "#{name}?" do !.named(name).empty? end end |