Class: Convergence::Index

Inherits:
Object
  • Object
show all
Defined in:
lib/convergence/index.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(index_name, index_columns, options) ⇒ Index

Returns a new instance of Index.



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/convergence/index.rb', line 4

def initialize(index_name, index_columns, options)
  @index_name = index_name
  @index_columns = [index_columns].flatten.map(&:to_s)
  @options = { name: @index_name }.merge(options)
  length = @options[:length]
  case length
  when Hash
    @options[:length] = Hash[length.map { |k, v| [k.to_s, v] }]
  when Integer
    @options[:length] = Hash[@index_columns.map { |col| [col, length] }]
  end
end

Instance Attribute Details

#index_columnsObject

Returns the value of attribute index_columns.



2
3
4
# File 'lib/convergence/index.rb', line 2

def index_columns
  @index_columns
end

#index_nameObject

Returns the value of attribute index_name.



2
3
4
# File 'lib/convergence/index.rb', line 2

def index_name
  @index_name
end

#optionsObject

Returns the value of attribute options.



2
3
4
# File 'lib/convergence/index.rb', line 2

def options
  @options
end

Instance Method Details

#quoted_columnsObject



17
18
19
20
21
# File 'lib/convergence/index.rb', line 17

def quoted_columns
  option_strings = Hash[@index_columns.map { |name| [name, ''] }]
  option_strings = add_index_length(option_strings, @index_columns, @options)
  @index_columns.map { |name| quote_column_name(name) + option_strings[name] }
end