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



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/active_record/connection_adapters/elasticsearch/schema_definitions/column_methods.rb', line 25

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.



19
20
21
# File 'lib/active_record/connection_adapters/elasticsearch/schema_definitions/column_methods.rb', line 19

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