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.
-
#by_section(section) ⇒ ActiveRecord::Relation
Finds all instances of this Attaching content that exist in a given section.
-
#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.
174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/cms/behaviors/attaching.rb', line 174 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).load = [] found_versions.each do |av| record = av.build_object_from_version << record end .delete_if { |value| value.deleted? } end |
#by_section(section) ⇒ ActiveRecord::Relation
Finds all instances of this Attaching content that exist in a given section.
126 127 128 129 130 |
# File 'lib/cms/behaviors/attaching.rb', line 126 def by_section(section) where(["#{SectionNode.table_name}.ancestry = ?", section.node.ancestry_path]) .includes(:attachments => :section_node) .references(:section_nodes) end |
#definitions_for(name) ⇒ Object
Return all definitions for a given class.
190 191 192 |
# File 'lib/cms/behaviors/attaching.rb', line 190 def definitions_for(name) Cms::Attachment.definitions[self.name][name] end |
#has_attachment(name, options = {}) ⇒ Object
Defines an single attachement with a given name.
137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/cms/behaviors/attaching.rb', line 137 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.
155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/cms/behaviors/attaching.rb', line 155 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 |