Class: Groonga::Schema::ColumnRenameDefinition

Inherits:
Object
  • Object
show all
Includes:
Path
Defined in:
lib/groonga/schema.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Path

#columns_directory_path, #rmdir_if_available, #tables_directory_path

Constructor Details

#initialize(current_name, new_name, options = {}) ⇒ ColumnRenameDefinition

Returns a new instance of ColumnRenameDefinition.



1595
1596
1597
1598
1599
1600
1601
# File 'lib/groonga/schema.rb', line 1595

def initialize(current_name, new_name, options={})
  @current_name = current_name
  @current_name = @current_name.to_s if @current_name.is_a?(Symbol)
  @new_name = new_name
  @new_name = @new_name.to_s if @new_name.is_a?(Symbol)
  @options = (options || {}).dup
end

Instance Attribute Details

#current_nameObject

Returns the value of attribute current_name.



1592
1593
1594
# File 'lib/groonga/schema.rb', line 1592

def current_name
  @current_name
end

#new_nameObject

Returns the value of attribute new_name.



1592
1593
1594
# File 'lib/groonga/schema.rb', line 1592

def new_name
  @new_name
end

#optionsObject (readonly)

Returns the value of attribute options.



1593
1594
1595
# File 'lib/groonga/schema.rb', line 1593

def options
  @options
end

Instance Method Details

#define(table_definition, table) ⇒ Object



1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
# File 'lib/groonga/schema.rb', line 1603

def define(table_definition, table)
  if @current_name.respond_to?(:call)
    current_name = @current_name.call(table_definition.context)
  else
    current_name = @current_name
  end
  column = table.column(current_name)

  if column.nil?
    raise ColumnNotExists.new(name)
  end

  column.rename(@new_name)
end