Class: CompositeContent::Slot

Inherits:
Model::Base
  • Object
show all
Defined in:
lib/composite_content/slot.rb

Overview

Slots are used as container for blocks collection.

Whether a model as one or more composite content slots does not matter: blocks are always contained in a slot. This allows to keep programming interface consistent between uses and ease future integration of multiple slots on model where only one was expected at first.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.block_classObject



22
23
24
# File 'lib/composite_content/slot.rb', line 22

def block_class
  @block_class ||= reflect_on_association(:blocks).class_name.constantize
end

.blockable_classesObject



26
27
28
29
30
31
32
# File 'lib/composite_content/slot.rb', line 26

def blockable_classes
  @blockable_classes ||= begin
    validators = block_class.validators_on_of_kinds(:blockable_type, :inclusion)
    types = validators.collect(&:options).collect { |opts| opts.fetch(:in) }.flatten.compact.uniq
    types.collect(&:constantize)
  end
end

.strong_parametersObject



34
35
36
37
38
39
40
41
42
# File 'lib/composite_content/slot.rb', line 34

def strong_parameters
  [
    :id,
    { blocks_attributes: block_strong_parameters_names + [
      { blockable_attributes: blockable_strong_parameters_names },
      :_destroy
    ] }
  ]
end

Instance Method Details

#parent_type=(class_name) ⇒ Object

Compatibility with parent models using Single Table Inheritance. See ActiveRecord::Associations::ClassMethods’s overview for more detail.



14
15
16
# File 'lib/composite_content/slot.rb', line 14

def parent_type=(class_name)
  super(class_name.constantize.base_class.to_s)
end