Class: Oinky::Model::Internal::IndexBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/oinky/dsl.rb

Instance Method Summary collapse

Constructor Details

#initialize(name, base = {}) ⇒ IndexBuilder

Returns a new instance of IndexBuilder.



12
13
14
15
16
17
18
# File 'lib/oinky/dsl.rb', line 12

def initialize(name, base = {})
  @h = {
    :name=>name.to_s, 
    :columns=>(base[:columns] or []).clone,
    :unique=>(base[:unique] or false)
  }
end

Instance Method Details

#add_column(colname, ascending = true) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/oinky/dsl.rb', line 20

def add_column(colname, ascending = true)
  if colname.is_a? Hash
    h = colname
  else
    h = {:name=>colname.to_s, :ascending=>ascending}
  end
  @h[:columns] << Oinky::Model.normalize_index_column_def(h)
end

#name(newname) ⇒ Object

override name



38
39
40
# File 'lib/oinky/dsl.rb', line 38

def name(newname)
  @h[:name] = newname.to_s
end

#set_unique(val) ⇒ Object



29
30
31
# File 'lib/oinky/dsl.rb', line 29

def set_unique(val)
  @h[:unique] = (val ? true : false)
end

#to_hObject



33
34
35
# File 'lib/oinky/dsl.rb', line 33

def to_h
  @h
end