module Elasticsearch::Persistence::Repository::ClassMethods

Public Instance Methods

create(options = {}, &block) click to toggle source

Initialize a repository instance. Optionally provide a block to define index mappings or

settings on the repository instance.

@example Create a new repository.

MyRepository.create(index_name: 'notes', klass: Note)

@example Create a new repository and evaluate a block on it.

MyRepository.create(index_name: 'notes', klass: Note) do
  mapping dynamic: 'strict' do
    indexes :title
  end
end

@param [ Hash ] options The options to use. @param [ Proc ] block A block to evaluate on the new repository instance.

@option options [ Symbol, String ] :index_name The name of the index. @option options [ Symbol, String ] :client The client used to handle requests to and from Elasticsearch. @option options [ Symbol, String ] :klass The class used to instantiate an object when documents are

deserialized. The default is nil, in which case the raw document will be returned as a Hash.

@option options [ Elasticsearch::Model::Indexing::Mappings, Hash ] :mapping The mapping for this index. @option options [ Elasticsearch::Model::Indexing::Settings, Hash ] :settings The settings for this index.

@since 6.0.0

# File lib/elasticsearch/persistence/repository.rb, line 68
def create(options = {}, &block)
  new(options).tap do |obj|
    obj.instance_eval(&block) if block_given?
  end
end