Class: Groonga::Schema::IndexColumnDefinition

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 = {}) ⇒ IndexColumnDefinition

Returns a new instance of IndexColumnDefinition.



796
797
798
799
800
801
# File 'lib/groonga/schema.rb', line 796

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

Instance Attribute Details

#nameObject

Returns the value of attribute name.



793
794
795
# File 'lib/groonga/schema.rb', line 793

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



794
795
796
# File 'lib/groonga/schema.rb', line 794

def options
  @options
end

#targetObject

Returns the value of attribute target.



793
794
795
# File 'lib/groonga/schema.rb', line 793

def target
  @target
end

Instance Method Details

#define(table_definition, table) ⇒ Object



803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
# File 'lib/groonga/schema.rb', line 803

def define(table_definition, table)
  target = @target
  unless target.is_a?(Groonga::Object)
    target = table_definition.context[target]
  end
  if target.nil?
    raise ArgumentError, "Unknown index target: #{@target.inspect}"
  end
  index = table.column(@name)
  if index
    return index if same_index?(table_definition, index, target)
    if @options.delete(:force)
      index.remove
    else
      raise ArgumentError,
            "the same name index column with " +
            "different target or options is " +
            "already defined: #{target.inspect}(#{@options.inspect}): " +
            "#{index.inspect}"
    end
  end
  index = table.define_index_column(@name,
                                    target.table,
                                    @options)
  index.source = target
  index
end