Class: Workarea::Content::Preset
- Inherits:
-
Object
- Object
- Workarea::Content::Preset
- Includes:
- ApplicationDocument
- Defined in:
- app/models/workarea/content/preset.rb
Instance Attribute Summary collapse
-
#data ⇒ Hash
The pieces of data passed to partials to render.
- #name ⇒ String
-
#type_id ⇒ Symbol
The content block type id.
Class Method Summary collapse
-
.create_from_block(attributes, block) ⇒ Workarea::Content::Preset
Create and persist a preset from an existing block.
Instance Method Summary collapse
-
#apply_block(block) ⇒ Boolean
Populate a preset from an existing Block.
-
#block_attributes ⇒ Hash
Return attributes needed to create a Block from a preset.
-
#type ⇒ Workarea::Content::BlockType
The BlockType that this block is.
Methods included from ApplicationDocument
Methods included from Sidekiq::Callbacks
assert_valid_config!, async, disable, enable, inline, #run_callbacks
Methods included from Mongoid::Document
Instance Attribute Details
#data ⇒ Hash
Returns 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 |
#type_id ⇒ Symbol
Returns 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.
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
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_attributes ⇒ Hash
Return attributes needed to create a Block from a preset.
52 53 54 |
# File 'app/models/workarea/content/preset.rb', line 52 def block_attributes as_json.slice('data', 'type_id') end |
#type ⇒ Workarea::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 |