Class: Elasticsearch::Persistence::Repository::Class

Inherits:
Object
  • Object
show all
Includes:
Model::Indexing::ClassMethods, Client::ClassMethods, Find, Naming, Search, Serialize, Store
Defined in:
lib/elasticsearch/persistence/repository/class.rb

Overview

The default repository class, to be used either directly, or as a gateway in a custom repository class

Examples:

Standalone use


repository = Elasticsearch::Persistence::Repository::Class.new
# => #<Elasticsearch::Persistence::Repository::Class ...>
repository.save(my_object)
# => {"_index"=> ... }

Shortcut use


repository = Elasticsearch::Persistence::Repository.new
# => #<Elasticsearch::Persistence::Repository::Class ...>

Configuration via a block


repository = Elasticsearch::Persistence::Repository.new do
  index 'my_notes'
end

# => #<Elasticsearch::Persistence::Repository::Class ...>
# > repository.save(my_object)
# => {"_index"=> ... }

Accessing the gateway in a custom class


class MyRepository
  include Elasticsearch::Persistence::Repository
end

repository = MyRepository.new

repository.gateway.client.info
# => {"status"=>200, "name"=>"Venom", ... }

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Search

#count, #search

Methods included from QueryCache

#cache_query, #store

Methods included from Find

#__find_many, #__find_one, #exists?, #find

Methods included from Store

#delete, #save, #update

Methods included from Serialize

#deserialize, #serialize

Methods included from Naming

#__extract_id_from_document, #__get_id_from_document, #__get_klass_from_type, #__get_type_from_class, #document_type, #document_type=, #index_name, #index_name=, #klass, #klass=

Methods included from Client::ClassMethods

#client, #client=

Constructor Details

#initialize(options = {}, &block) ⇒ Class

Returns a new instance of Class.



52
53
54
55
56
# File 'lib/elasticsearch/persistence/repository/class.rb', line 52

def initialize(options={}, &block)
  @options = options
  index_name options.delete(:index)
  block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given?
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



50
51
52
# File 'lib/elasticsearch/persistence/repository/class.rb', line 50

def options
  @options
end

Instance Method Details

#hostnil, Class

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return the “host” class, if this repository is a gateway hosted in another class

Returns:



64
65
66
# File 'lib/elasticsearch/persistence/repository/class.rb', line 64

def host
  options[:host]
end