module PGInheritance::ActiveRecord::SchemaStatements

Constants

INDEX_OPTIONS

Public Instance Methods

create_table(table_name, options = {}) click to toggle source
Calls superclass method
# File lib/pg_inheritance/active_record/schema_statements.rb, line 10
def create_table(table_name, options = {})
  parent_table = options.delete(:inherits)

  prepare_options(parent_table, options)

  table_name = prepare_table_name(table_name, options)

  super(table_name, options)
end

Private Instance Methods

add_inheritance_query(inherited_table, options) click to toggle source
# File lib/pg_inheritance/active_record/schema_statements.rb, line 34
def add_inheritance_query(inherited_table, options)
  return unless inherited_table

  options[:options] = build_inherits_option(inherited_table)
end
build_inherits_option(inherited_table) click to toggle source
# File lib/pg_inheritance/active_record/schema_statements.rb, line 48
def build_inherits_option(inherited_table)
  "INHERITS (#{inherited_table})"
end
prepare_options(inherited_table, options) click to toggle source
# File lib/pg_inheritance/active_record/schema_statements.rb, line 22
def prepare_options(inherited_table, options)
  remove_pk_option(options)
  add_inheritance_query(inherited_table, options)
end
prepare_table_name(table_name, options) click to toggle source
# File lib/pg_inheritance/active_record/schema_statements.rb, line 40
def prepare_table_name(table_name, options)
  schema = options.delete(:schema)

  return table_name unless schema

  "#{schema}.#{table_name}"
end
remove_pk_option(options) click to toggle source
# File lib/pg_inheritance/active_record/schema_statements.rb, line 27
def remove_pk_option(options)
  return unless options[:inherits]

  options[:id] = false
  options.delete(:primary_key)
end