Class: Workarea::Content::Preset

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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 Attribute Details

#dataHash

Returns the pieces of data passed to partials to render.

Returns:

  • (Hash)

    the pieces of data passed to partials to render



32
# File 'app/models/workarea/content/preset.rb', line 32

field :data, type: Hash, default: {}, localize: true

#nameString

Returns:



27
# File 'app/models/workarea/content/preset.rb', line 27

field :name, type: String

#type_idSymbol

Returns the content block type id.

Returns:

  • (Symbol)

    the content block type id



22
# File 'app/models/workarea/content/preset.rb', line 22

field :type_id, type: Symbol

Class Method Details

.create_from_block(attributes, block) ⇒ Workarea::Content::Preset

Create and persist a preset from an existing block.

Parameters:

Returns:



13
14
15
16
17
# File 'app/models/workarea/content/preset.rb', line 13

def self.create_from_block(attributes, block)
  instance = new(attributes)
  instance.apply_block(block)
  instance.save
end

Instance Method Details

#apply_block(block) ⇒ Boolean

Populate a preset from an existing Block

Parameters:

Returns:

  • (Boolean)


42
43
44
45
# File 'app/models/workarea/content/preset.rb', line 42

def apply_block(block)
  self.attributes = block.as_json.slice('data', 'type_id')
  self.name ||= block.type.name
end

#block_attributesHash

Return attributes needed to create a Block from a preset.

Returns:

  • (Hash)


52
53
54
# File 'app/models/workarea/content/preset.rb', line 52

def block_attributes
  as_json.slice('data', 'type_id')
end

#typeWorkarea::Content::BlockType

The BlockType that this block is. See documentation for Workarea.define_content_block_types for info how to define block types.



61
62
63
# File 'app/models/workarea/content/preset.rb', line 61

def type
  Workarea.config.content_block_types.detect { |bt| bt.id == type_id }
end