Class: Workarea::Content::BlockDraft

Inherits:
Object
  • Object
show all
Includes:
ApplicationDocument
Defined in:
app/models/workarea/content/block_draft.rb

Instance Method Summary collapse

Methods included from ApplicationDocument

#releasable?

Methods included from Sidekiq::Callbacks

add_worker, assert_valid_config!, async, caching_classes?, disable, enable, inline, #run_callbacks, workers, workers_list

Methods included from Mongoid::Document

#embedded_children

Instance Method Details

#block_typeObject



26
27
28
29
# File 'app/models/workarea/content/block_draft.rb', line 26

def block_type
  return unless type_id.present?
  Configuration::ContentBlocks.types.detect { |bt| bt.id == type_id.to_sym }
end

#contentObject



22
23
24
# File 'app/models/workarea/content/block_draft.rb', line 22

def content
  Content.find(content_id)
end

#to_blockObject



37
38
39
40
41
# File 'app/models/workarea/content/block_draft.rb', line 37

def to_block
  result = Content::Block.instantiate(as_document.except('content_id'))
  result.new_record = true
  result
end

#typecast_data!Object



31
32
33
34
35
# File 'app/models/workarea/content/block_draft.rb', line 31

def typecast_data!
  return unless type_id.present? && data.present?
  self.data = block_type.try(:typecast!, data)
  self
end