Class: Spina::Parts::BlockReference

Inherits:
Base
  • Object
show all
Includes:
BlockFilterable
Defined in:
app/models/spina/parts/block_reference.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from BlockFilterable

#available_blocks

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



10
11
12
# File 'app/models/spina/parts/block_reference.rb', line 10

def options
  @options
end

Instance Method Details

#contentObject



12
13
14
15
16
17
18
# File 'app/models/spina/parts/block_reference.rb', line 12

def content
  if custom_block_name.present?
    custom_block_record
  else
    ::Spina::Blocks::Block.active.find_by(id: block_id)
  end
end

#custom_block_nameObject

Returns the custom_block key from options, supporting both symbol and string keys



21
22
23
24
25
# File 'app/models/spina/parts/block_reference.rb', line 21

def custom_block_name
  return if options.blank?

  options[:custom_block] || options["custom_block"]
end

#custom_block_recordObject

Looks up the custom block record by key



28
29
30
31
32
# File 'app/models/spina/parts/block_reference.rb', line 28

def custom_block_record
  return if custom_block_name.blank?

  ::Spina::Blocks::Block.find_by(key: custom_block_name)
end