class GroongaSchema::Column

Attributes

flags[RW]
name[R]
reference_value_type[W]
sources[RW]
table_name[R]
type[RW]
value_type[RW]

Public Class Methods

new(table_name, name) click to toggle source
# File lib/groonga-schema/column.rb, line 27
def initialize(table_name, name)
  @table_name = table_name
  @name = name
  @type = :scalar
  @flags = []
  @value_type = "ShortText"
  @sources = []
  @reference_value_type = false
  @related_columns = []
end

Public Instance Methods

==(other) click to toggle source
# File lib/groonga-schema/column.rb, line 55
def ==(other)
  return false unless other.is_a?(self.class)

  @table_name == other.table_name and
    @name == other.name and
    @type == other.type and
    @flags.sort == other.flags.sort and
    @value_type == other.value_type and
    @sources == other.sources
end
apply_column(column) click to toggle source
# File lib/groonga-schema/column.rb, line 47
def apply_column(column)
  self.type                 = column.type
  self.flags                = column.flags
  self.value_type           = column.value_type
  self.sources              = column.sources
  self.reference_value_type = column.reference_value_type?
end
apply_command(command) click to toggle source
# File lib/groonga-schema/column.rb, line 42
def apply_command(command)
  applier = CommandApplier.new(self, command)
  applier.apply
end
reference_value_type?() click to toggle source
# File lib/groonga-schema/column.rb, line 38
def reference_value_type?
  @reference_value_type
end
to_copy_groonga_command(to_table_name, to_name) click to toggle source
# File lib/groonga-schema/column.rb, line 74
def to_copy_groonga_command(to_table_name, to_name)
  column_copy_command(to_table_name, to_name)
end
to_create_groonga_command() click to toggle source
# File lib/groonga-schema/column.rb, line 66
def to_create_groonga_command
  column_create_command(@name)
end
to_migrate_finish_groonga_commands() click to toggle source
# File lib/groonga-schema/column.rb, line 89
def to_migrate_finish_groonga_commands
  [
    column_remove_command(old_name),
  ]
end
to_migrate_start_groonga_commands() click to toggle source
# File lib/groonga-schema/column.rb, line 78
def to_migrate_start_groonga_commands
  commands = []
  commands << column_create_command(new_name)
  if type != :index
    commands << column_copy_command(@table_name, new_name)
  end
  commands << column_rename_command(@name, old_name)
  commands << column_rename_command(new_name, @name)
  commands
end
to_remove_groonga_command() click to toggle source
# File lib/groonga-schema/column.rb, line 70
def to_remove_groonga_command
  column_remove_command(@name)
end

Private Instance Methods

column_copy_command(to_table_name, to_name) click to toggle source
# File lib/groonga-schema/column.rb, line 126
def column_copy_command(to_table_name, to_name)
  arguments = {
    "from_table" => @table_name,
    "from_name"  => @name,
    "to_table"   => to_table_name,
    "to_name"    => to_name,
  }
  Groonga::Command::ColumnCopy.new(arguments)
end
column_create_command(name) click to toggle source
# File lib/groonga-schema/column.rb, line 104
def column_create_command(name)
  flags_value = [type_flag, *flags].join("|")
  sources_value = @sources.join(",")
  sources_value = nil if sources_value.empty?
  arguments = {
    "table"  => @table_name,
    "name"   => name,
    "flags"  => flags_value,
    "type"   => @value_type,
    "source" => sources_value,
  }
  Groonga::Command::ColumnCreate.new(arguments)
end
column_remove_command(name) click to toggle source
# File lib/groonga-schema/column.rb, line 118
def column_remove_command(name)
  arguments = {
    "table"  => @table_name,
    "name"   => name,
  }
  Groonga::Command::ColumnRemove.new(arguments)
end
column_rename_command(name, new_name) click to toggle source
# File lib/groonga-schema/column.rb, line 136
def column_rename_command(name, new_name)
  arguments = {
    "table"    => @table_name,
    "name"     => name,
    "new_name" => new_name,
  }
  Groonga::Command::ColumnRename.new(arguments)
end
new_name() click to toggle source
# File lib/groonga-schema/column.rb, line 100
def new_name
  "#{@name}_new"
end
old_name() click to toggle source
# File lib/groonga-schema/column.rb, line 96
def old_name
  "#{@name}_old"
end
type_flag() click to toggle source
# File lib/groonga-schema/column.rb, line 145
def type_flag
  case @type
  when :scalar
    "COLUMN_SCALAR"
  when :vector
    "COLUMN_VECTOR"
  when :index
    "COLUMN_INDEX"
  else
    "COLUMN_SCALAR"
  end
end