Module: Elasticsearch::Persistence::Repository

Extended by:
ActiveSupport::Autoload
Defined in:
lib/elasticsearch/persistence/repository.rb,
lib/elasticsearch/persistence.rb,
lib/elasticsearch/persistence/repository/find.rb,
lib/elasticsearch/persistence/repository/class.rb,
lib/elasticsearch/persistence/repository/store.rb,
lib/elasticsearch/persistence/repository/naming.rb,
lib/elasticsearch/persistence/repository/search.rb,
lib/elasticsearch/persistence/repository/serialize.rb,
lib/elasticsearch/persistence/repository/response/results.rb

Overview

When included, creates an instance of the Repository class as a “gateway”

Examples:

Include the repository in a custom class


require 'elasticsearch/persistence'

class MyRepository
  include Elasticsearch::Persistence::Repository
end

Defined Under Namespace

Modules: Find, Naming, Response, Search, Serialize, Store Classes: Class, DocumentNotFound

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/elasticsearch/persistence/repository.rb', line 31

def self.included(base)
  gateway = Elasticsearch::Persistence::Repository::Class.new host: base

  # Define the instance level gateway
  #
  base.class_eval do
    define_method :gateway do
      @gateway ||= gateway
    end

    include GatewayDelegation
  end

  # Define the class level gateway
  #
  (class << base; self; end).class_eval do
    define_method :gateway do |&block|
      @gateway ||= gateway
      @gateway.instance_eval(&block) if block
      @gateway
    end

    include GatewayDelegation
  end

  # Catch repository methods (such as `serialize` and others) defined in the receiving class,
  # and overload the default definition in the gateway
  #
  def base.method_added(name)
    if :gateway != name && respond_to?(:gateway) && (gateway.public_methods - Object.public_methods).include?(name)
      gateway.define_singleton_method(name, self.new.method(name).to_proc)
    end
  end
end

.new(options = {}, &block) ⇒ Object

Shortcut method to allow concise repository initialization

Examples:

Create a new default repository

repository = Elasticsearch::Persistence::Repository.new


72
73
74
# File 'lib/elasticsearch/persistence/repository.rb', line 72

def new(options={}, &block)
  Elasticsearch::Persistence::Repository::Class.new( {index: 'repository'}.merge(options), &block )
end