Class: StagingTable::ModelFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/staging_table/model_factory.rb

Class Method Summary collapse

Class Method Details

.build(source_model, table_name, excluded_columns: []) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/staging_table/model_factory.rb', line 5

def self.build(source_model, table_name, excluded_columns: [])
  Class.new(source_model) do
    self.table_name = table_name
    self.ignored_columns = excluded_columns

    # Ensure we don't inherit STI behavior unless intended for the temp table
    self.inheritance_column = nil unless source_model.inheritance_column == "type" && source_model.columns_hash["type"]

    def self.model_name
      ActiveModel::Name.new(self, nil, superclass.name)
    end

    # Prevent the dynamic class from being added to the global constant namespace
    def self.name
      "#{superclass.name}::Staging_#{table_name}"
    end
  end
end