Class: Workarea::Content::BlockDraft

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

Instance Method Summary collapse

Methods included from Releasable

#changesets_with_children, #destroy, #in_release, #release_changes, #release_originals, #save_changeset, #skip_changeset, #without_release

Methods included from Segmentable

#active?, #active_segment_ids_with_children, #segmented?, #segments

Methods included from Release::Activation

#activate_with?, #create_activation_changeset, #save_activate_with, #was_active?

Methods included from ApplicationDocument

#releasable?

Methods included from Sidekiq::Callbacks

assert_valid_config!, async, disable, enable, inline, #run_callbacks

Methods included from Mongoid::Document

#embedded_children

Instance Method Details

#block_typeObject



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

def block_type
  return unless type_id.present?
  Workarea.config.content_block_types.detect { |bt| bt.id == type_id.to_sym }
end

#contentObject



19
20
21
# File 'app/models/workarea/content/block_draft.rb', line 19

def content
  Content.find(content_id)
end

#to_blockObject



34
35
36
37
38
# File 'app/models/workarea/content/block_draft.rb', line 34

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

#typecast_data!Object



28
29
30
31
32
# File 'app/models/workarea/content/block_draft.rb', line 28

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