Sha256: 5d4d37b3297325389f0c9f10bd467319bf13c838cad2d7360048f25d91bc23e3

Contents?: true

Size: 1.04 KB

Versions: 2

Compression:

Stored size: 1.04 KB

Contents

require "active_support/all"
require "es_searchable/version"
require "es_searchable/configurable"

module EsSearchable
	extend Configurable
  extend ActiveSupport::Concern

	included do
    class << self
			extend Forwardable
			SearchMethods.each do |meth|
				def_delegator :es_collection, meth, "es_#{meth}"
			end
		end
	end

	module ClassMethods
		def es_collection
			@es_collection = SearchCollection.new(self)
		end

		def handle_es_response(es_coll)
			es_coll
		end

		def client
			@client ||= Elasticsearch::Client.new(EsSearchable.options.slice(
				:log, :retry_on_failure, :reload_on_failure, :hosts, :logger
			))
		end

		def es_search(conditions)
			client.search(index: index, body: conditions)
		end

		def es_index(index)
			@index = index
		end

		def index
			@index ||= self.name.demodulize.downcase.pluralize
		end

		def method_missing(meth, *args, &blk)
			case meth
			when /(.*)_(gt|lt|gte|lte|between|like)/
				es_collection.send(meth, *args, &blk)
			else
				super
			end
		end
	end
end

require "es_searchable/search_collection"

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
es_searchable-0.2.1 lib/es_searchable.rb
es_searchable-0.2.0 lib/es_searchable.rb