Sha256: 54348c4df75e5954aebbce5c06464f897e7385ae3e05d57eb12c37c4c93200e8

Contents?: true

Size: 1.05 KB

Versions: 8

Compression:

Stored size: 1.05 KB

Contents

module Cms
  class AbstractFileBlock < ActiveRecord::Base


    self.table_name = Namespacing.prefix("file_blocks")

    validates_presence_of :name

    scope :by_section, lambda { |section| {
        :include => {:attachments => :section_node},
        :conditions => ["#{SectionNode.table_name}.ancestry = ?", section.node.ancestry_path]}
    }

    # Return the parent section for this block.
    # @return [Cms::Section]
    def parent
      file.parent
    end

    # Exists here so FileBrowser can polymorphically call file_size on Page, Images, Files, etc.
    def file_size
      file.size.round_bytes
    end

    def path
      file.url
    end

    def self.publishable?
      true
    end

    def set_attachment_path
      if @attachment_file_path && @attachment_file_path != attachment.file_path
        attachment.file_path = @attachment_file_path
      end
    end

    def set_attachment_section
      if @attachment_section_id && @attachment_section_id != attachment.section
        attachment.section_id = @attachment_section_id
      end
    end

  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
browsercms-3.5.7 app/models/cms/abstract_file_block.rb
browsercms-3.5.6 app/models/cms/abstract_file_block.rb
browsercms-3.5.5 app/models/cms/abstract_file_block.rb
browsercms-3.5.4 app/models/cms/abstract_file_block.rb
browsercms-3.5.3 app/models/cms/abstract_file_block.rb
browsercms-3.5.2 app/models/cms/abstract_file_block.rb
browsercms-3.5.1 app/models/cms/abstract_file_block.rb
browsercms-3.5.0 app/models/cms/abstract_file_block.rb