Class: Groonga::Schema::ColumnDefinition

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

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ ColumnDefinition

Returns a new instance of ColumnDefinition.



744
745
746
747
748
749
# File 'lib/groonga/schema.rb', line 744

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.



741
742
743
# File 'lib/groonga/schema.rb', line 741

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



742
743
744
# File 'lib/groonga/schema.rb', line 742

def options
  @options
end

#typeObject

Returns the value of attribute type.



741
742
743
# File 'lib/groonga/schema.rb', line 741

def type
  @type
end

Instance Method Details

#define(table_definition, table) ⇒ Object



751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
# File 'lib/groonga/schema.rb', line 751

def define(table_definition, table)
  column = table.column(@name)
  if column
    return column if same_column?(table_definition, column)
    if @options.delete(:force)
      column.remove
    else
      raise ArgumentError,
            "the same name column with different type is " +
            "already defined: #{@type.inspect}(#{@options.inspect}): " +
            "#{column.inspect}"
    end
  end
  table.define_column(@name,
                      Schema.normalize_type(@type),
                      @options)
end