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.



1752
1753
1754
1755
1756
1757
# File 'lib/groonga/schema.rb', line 1752

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.



1749
1750
1751
# File 'lib/groonga/schema.rb', line 1749

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



1750
1751
1752
# File 'lib/groonga/schema.rb', line 1750

def options
  @options
end

#typeObject

Returns the value of attribute type.



1749
1750
1751
# File 'lib/groonga/schema.rb', line 1749

def type
  @type
end

Instance Method Details

#define(table_definition, table) ⇒ Object



1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
# File 'lib/groonga/schema.rb', line 1759

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