class Miguel::Schema::Index

Class representing database index.

Constants

IGNORED_OPTS

Options we ignore when comparing.

Attributes

columns[R]

Index column(s) and options.

opts[R]

Index column(s) and options.

Public Class Methods

new( columns, opts = {} ) click to toggle source

Create new index for given column(s).

# File lib/miguel/schema.rb, line 211
def initialize( columns, opts = {} )
  @columns = [ *columns ]
  @opts = opts
end

Public Instance Methods

==(other) click to toggle source

Compare one index with another one.

# File lib/miguel/schema.rb, line 227
def == other
  other.is_a?( Index ) &&
  columns == other.columns &&
  canonic_opts == other.canonic_opts
end
canonic_opts() click to toggle source

Get the index options, in a canonic way.

# File lib/miguel/schema.rb, line 220
def canonic_opts
  o = { :unique => false }
  o.merge!( opts )
  o.delete_if{ |key, value| IGNORED_OPTS.include? key }
end
dump( out ) click to toggle source

Dump index definition.

# File lib/miguel/schema.rb, line 234
def dump( out )
  out << "index #{out_columns}#{out_opts}"
end