Class: CompositeContent::Model::Builder::Block
- Defined in:
- lib/composite_content/model/builder/block.rb
Overview
Class builder for Block models
Every composite content slot as its own block class, subclass of CompositeContent::Block. This allows to set distinct validations on allowed block types used in each composite content.
Constant Summary
Constants inherited from Base
CompositeContent::Model::Builder::Base::BLOCK_SUFFIX, CompositeContent::Model::Builder::Base::SLOT_SUFFIX
Instance Method Summary collapse
Methods inherited from Base
Instance Method Details
#build_class(parent, association, types = []) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/composite_content/model/builder/block.rb', line 14 def build_class(parent, association, types = []) Class.new(::CompositeContent::Block).tap do |klass| klass.belongs_to :slot, class_name: classname_for_slot(parent, association), inverse_of: :blocks klass.delegated_type :blockable, types: blockable_types(types), dependent: :destroy klass.accepts_nested_attributes_for :blockable, reject_if: :all_blank klass.validates_associated :blockable klass.validates :blockable_type, inclusion: { in: blockable_types(types) } end end |