Class: Miguel::Schema::Index

Inherits:
Object
  • Object
show all
Includes:
Output
Defined in:
lib/miguel/schema.rb

Overview

Class representing database index.

Constant Summary collapse

IGNORED_OPTS =

Options we ignore when comparing.

[ :null ]

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Output

#out_canonic_opts, #out_columns, #out_default, #out_default_opts, #out_name, #out_opts, #out_table_name, #out_type

Constructor Details

#initialize(columns, opts = {}) ⇒ Index

Create new index for given column(s).



211
212
213
214
# File 'lib/miguel/schema.rb', line 211

def initialize( columns, opts = {} )
  @columns = [ *columns ]
  @opts = opts
end

Instance Attribute Details

#columnsObject (readonly)

Index column(s) and options.



208
209
210
# File 'lib/miguel/schema.rb', line 208

def columns
  @columns
end

#optsObject (readonly)

Index column(s) and options.



208
209
210
# File 'lib/miguel/schema.rb', line 208

def opts
  @opts
end

Instance Method Details

#==(other) ⇒ Object

Compare one index with another one.



227
228
229
230
231
# File 'lib/miguel/schema.rb', line 227

def == other
  other.is_a?( Index ) &&
  columns == other.columns &&
  canonic_opts == other.canonic_opts
end

#canonic_optsObject

Get the index options, in a canonic way.



220
221
222
223
224
# 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) ⇒ Object

Dump index definition.



234
235
236
# File 'lib/miguel/schema.rb', line 234

def dump( out )
  out << "index #{out_columns}#{out_opts}"
end