module Elasticsearch::Persistence::Repository
When included, creates an instance of the {Repository::Class Repository} class as a “gateway”
@example Include the repository in a custom class
require 'elasticsearch/persistence' class MyRepository include Elasticsearch::Persistence::Repository end
Public Class Methods
included(base)
click to toggle source
# 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)
click to toggle source
Shortcut method to allow concise repository initialization
@example Create a new default repository
repository = Elasticsearch::Persistence::Repository.new
# File lib/elasticsearch/persistence/repository.rb, line 72 def new(options={}, &block) Elasticsearch::Persistence::Repository::Class.new( {index: 'repository'}.merge(options), &block ) end
Private Instance Methods
new(options={}, &block)
click to toggle source
Shortcut method to allow concise repository initialization
@example Create a new default repository
repository = Elasticsearch::Persistence::Repository.new
# File lib/elasticsearch/persistence/repository.rb, line 72 def new(options={}, &block) Elasticsearch::Persistence::Repository::Class.new( {index: 'repository'}.merge(options), &block ) end