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.



1694
1695
1696
1697
1698
1699
# File 'lib/groonga/schema.rb', line 1694

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.



1691
1692
1693
# File 'lib/groonga/schema.rb', line 1691

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



1692
1693
1694
# File 'lib/groonga/schema.rb', line 1692

def options
  @options
end

#typeObject

Returns the value of attribute type.



1691
1692
1693
# File 'lib/groonga/schema.rb', line 1691

def type
  @type
end

Instance Method Details

#define(table_definition, table) ⇒ Object



1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
# File 'lib/groonga/schema.rb', line 1701

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