Module: ActiveRecord::ConnectionAdapters::Elasticsearch::ColumnMethods

Extended by:
ActiveSupport::Concern
Included in:
TableDefinition
Defined in:
lib/active_record/connection_adapters/elasticsearch/schema_definitions/column_methods.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.define_column_methods(*column_types) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/active_record/connection_adapters/elasticsearch/schema_definitions/column_methods.rb', line 34

def define_column_methods(*column_types)
  # :nodoc:
  column_types.each do |column_type|
    module_eval <<-RUBY, __FILE__, __LINE__ + 1
    def #{column_type}(*names, **options)
      raise ArgumentError, "Missing column name(s) for #{column_type}" if names.empty?
      names.each { |name| mapping(name, :#{column_type}, **options) }
    end
    RUBY
  end
end

Instance Method Details

#primary_key(name, type = :primary_key, **options) ⇒ Object

Appends a primary key definition to the table definition. Can be called multiple times, but this is probably not a good idea.



28
29
30
# File 'lib/active_record/connection_adapters/elasticsearch/schema_definitions/column_methods.rb', line 28

def primary_key(name, type = :primary_key, **options)
  mapping(name, type, **options.merge(primary_key: true, auto_increment: true))
end