Class: Groonga::Schema::ColumnDefinition

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(name, options = {}) ⇒ ColumnDefinition

Returns a new instance of ColumnDefinition.



1475
1476
1477
1478
1479
1480
# File 'lib/groonga/schema.rb', line 1475

def initialize(name, options={})
  @name = name
  @name = @name.to_s if @name.is_a?(Symbol)
  @options = (options || {}).dup
  @type = nil
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



1472
1473
1474
# File 'lib/groonga/schema.rb', line 1472

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



1473
1474
1475
# File 'lib/groonga/schema.rb', line 1473

def options
  @options
end

#typeObject

Returns the value of attribute type.



1472
1473
1474
# File 'lib/groonga/schema.rb', line 1472

def type
  @type
end

Instance Method Details

#define(table_definition, table) ⇒ Object



1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
# File 'lib/groonga/schema.rb', line 1482

def define(table_definition, table)
  context = table_definition.context
  column = table.column(@name)
  options = define_options(context, table)
  if column
    return column if same_column?(context, column)
    if @options[:force]
      column.remove
    else
      raise ColumnCreationWithDifferentOptions.new(column, options)
    end
  end
  table.define_column(@name,
                      resolved_type(context),
                      options)
end