Class: Mv::Core::Constraint::Builder::Index

Inherits:
Base
  • Object
show all
Defined in:
lib/mv/core/constraint/builder/index.rb

Instance Attribute Summary

Attributes inherited from Base

#constraint

Instance Method Summary collapse

Methods inherited from Base

#initialize, #validation_builders, validation_builders_factory

Constructor Details

This class inherits a constructor from Mv::Core::Constraint::Builder::Base

Instance Method Details

#createObject



8
9
10
11
12
13
14
15
# File 'lib/mv/core/constraint/builder/index.rb', line 8

def create
  super

  constraint.validations.group_by(&:table_name).each do |table_name, validations|
    remove_index(table_name)
    add_index(table_name, validations.collect(&:column_name))
  end
end

#deleteObject



17
18
19
20
21
22
23
# File 'lib/mv/core/constraint/builder/index.rb', line 17

def delete
  super

  constraint.validations.group_by(&:table_name).each do |table_name, validations|
    remove_index(table_name)
  end
end

#update(new_constraint_builder) ⇒ Object



25
26
27
28
29
30
# File 'lib/mv/core/constraint/builder/index.rb', line 25

def update new_constraint_builder
  super

  delete
  new_constraint_builder.create
end