Class: Chicago::Database::IndexGenerator Private

Inherits:
Object
  • Object
show all
Defined in:
lib/chicago/database/index_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.



4
5
6
# File 'lib/chicago/database/index_generator.rb', line 4

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.



8
9
10
11
12
13
14
15
16
17
# File 'lib/chicago/database/index_generator.rb', line 8

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.merge!(:_inserted_at_idx => {:columns => :_inserted_at, :unique => false})
  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.



19
20
21
22
23
24
25
26
# File 'lib/chicago/database/index_generator.rb', line 19

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.



28
29
30
31
32
# File 'lib/chicago/database/index_generator.rb', line 28

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