Class: Miguel::Schema::Index
- Inherits:
-
Object
- Object
- Miguel::Schema::Index
- 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
-
#columns ⇒ Object
readonly
Index column(s) and options.
-
#opts ⇒ Object
readonly
Index column(s) and options.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Compare one index with another one.
-
#canonic_opts ⇒ Object
Get the index options, in a canonic way.
-
#dump(out) ⇒ Object
Dump index definition.
-
#initialize(columns, opts = {}) ⇒ Index
constructor
Create new index for given column(s).
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
#columns ⇒ Object (readonly)
Index column(s) and options.
208 209 210 |
# File 'lib/miguel/schema.rb', line 208 def columns @columns end |
#opts ⇒ Object (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_opts ⇒ Object
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 |