Class: Cms::AbstractFileBlock

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/cms/abstract_file_block.rb

Direct Known Subclasses

FileBlock, ImageBlock

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.publishable?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'app/models/cms/abstract_file_block.rb', line 33

def self.publishable?
  true
end

.with_parent_id(parent_id) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'app/models/cms/abstract_file_block.rb', line 5

def self.with_parent_id(parent_id)
  if parent_id == 'all'
    where(true) # Empty scope for chaining
  else
    self.includes({:attachments => :section_node})
        .references(:section_node)
        .where(["#{"cms_section_nodes"}.ancestry = ?",  Section.find(parent_id).ancestry_path])

  end
end

Instance Method Details

#file_sizeObject

Exists here so FileBrowser can polymorphically call file_size on Page, Images, Files, etc.



25
26
27
# File 'app/models/cms/abstract_file_block.rb', line 25

def file_size
  file.size.round_bytes
end

#parentCms::Section

Return the parent section for this block.

Returns:



20
21
22
# File 'app/models/cms/abstract_file_block.rb', line 20

def parent
  file.parent
end

#pathObject



29
30
31
# File 'app/models/cms/abstract_file_block.rb', line 29

def path
  file.url
end

#set_attachment_pathObject



37
38
39
40
41
# File 'app/models/cms/abstract_file_block.rb', line 37

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

#set_attachment_sectionObject



43
44
45
46
47
# File 'app/models/cms/abstract_file_block.rb', line 43

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