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
-
#build_essence(attributes = {}) ⇒ Object
Build essence from definition.
-
#create_essence!(attrs = {}) ⇒ Object
Creates essence from definition.
-
#definition ⇒ Object
Returns the definition hash from
elements.ymlfile.
Instance Method Details
#build_essence(attributes = {}) ⇒ Object
Build essence from definition.
If an optional type is passed, this type of essence gets created.
118 119 120 121 122 |
# File 'app/models/alchemy/content/factory.rb', line 118 def build_essence(attributes = {}) self.essence = essence_class.new( { content: self, ingredient: default_value }.merge(attributes) ) end |
#create_essence!(attrs = {}) ⇒ Object
Creates essence from definition.
If an optional type is passed, this type of essence gets created.
128 129 130 131 |
# File 'app/models/alchemy/content/factory.rb', line 128 def create_essence!(attrs = {}) build_essence(attrs).save! save! end |
#definition ⇒ Object
Returns the definition hash from elements.yml file.
106 107 108 109 110 111 112 |
# File 'app/models/alchemy/content/factory.rb', line 106 def definition if element.blank? log_warning "Content with id #{id} is missing its Element." return {} end element.content_definition_for(name) || {} end |