Class: Chicago::Database::IndexGenerator Private

Inherits:
Object
  • Object
show all
Defined in:
lib/chicago/database/schema_generator.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Constructor Details

#initialize(table) ⇒ IndexGenerator

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of IndexGenerator.



85
86
87
# File 'lib/chicago/database/schema_generator.rb', line 85

def initialize(table)
  @table = table
end

Instance Method Details

#indexesObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



89
90
91
92
93
94
95
96
97
# File 'lib/chicago/database/schema_generator.rb', line 89

def indexes
  indexes = @table.columns.select(&:indexed?).inject({}) do |hsh, d|
    hsh.merge("#{d.name}_idx".to_sym => {
                :columns => d.database_name,
                :unique => d.unique?})
  end
  indexes.merge!(natural_key_index) if @table.natural_key
  indexes
end

#natural_key_indexObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



99
100
101
102
103
104
105
106
# File 'lib/chicago/database/schema_generator.rb', line 99

def natural_key_index
  {
    "#{@table.natural_key.first}_idx".to_sym => {
      :columns => natural_key_index_columns,
      :unique => true
    }
  }
end

#natural_key_index_columnsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



108
109
110
111
112
# File 'lib/chicago/database/schema_generator.rb', line 108

def natural_key_index_columns
  @table.natural_key.map do |name|
    @table[name].database_name rescue raise MissingDefinitionError.new("Column #{name} is not defined in #{@table.name}")
  end
end