Class: Wallaby::ActiveRecord::ModelDecorator::FieldsBuilder::StiBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/adapters/wallaby/active_record/model_decorator/fields_builder/sti_builder.rb

Overview

This class updates the field metadata’s value of type and sti_class_list for STI (Single Table Inheritance) model

Instance Method Summary collapse

Constructor Details

#initialize(model_class) ⇒ StiBuilder

Returns a new instance of StiBuilder.

Parameters:

  • model_class (Class)


11
12
13
# File 'lib/adapters/wallaby/active_record/model_decorator/fields_builder/sti_builder.rb', line 11

def initialize(model_class)
  @model_class = model_class
end

Instance Method Details

#update(metadata, column) ⇒ Object

Update the field metadata’s value for type and sti_class_list

Parameters:

  • metadata (Hash)
  • column (ActiveRecord::ConnectionAdapters::Column)


18
19
20
21
22
23
# File 'lib/adapters/wallaby/active_record/model_decorator/fields_builder/sti_builder.rb', line 18

def update(, column)
  return unless @model_class.inheritance_column == column.name

  [:type] = 'sti'
  [:sti_class_list] = sti_list(find_sti_parent_of(@model_class))
end