Module: Alchemy::Content::Factory

Extended by:
ActiveSupport::Concern
Included in:
Alchemy::Content
Defined in:
app/models/alchemy/content/factory.rb

Overview

Holds everything concerning the building and creating of contents and the related essence object.

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#build_essence(type = essence_type) ⇒ Object

Build essence from definition.

If an optional type is passed, this type of essence gets created.


120
121
122
123
124
# File 'app/models/alchemy/content/factory.rb', line 120

def build_essence(type = essence_type)
  self.essence = essence_class(type).new({
    ingredient: default_value,
  })
end

#create_essence!(type = nil) ⇒ Object

Creates essence from definition.

If an optional type is passed, this type of essence gets created.


130
131
132
133
# File 'app/models/alchemy/content/factory.rb', line 130

def create_essence!(type = nil)
  build_essence(type).save!
  save!
end

#definitionObject

Returns the definition hash from elements.yml file.


108
109
110
111
112
113
114
# File 'app/models/alchemy/content/factory.rb', line 108

def definition
  if element.blank?
    log_warning "Content with id #{id} is missing its Element."
    return {}
  end
  element.content_definition_for(name) || {}
end