Sha256: 9a21bb1c79294bb4a2ca5b8e6819fd67d0aa3eceb87e0ba0f29e4ef61495e138

Contents?: true

Size: 810 Bytes

Versions: 2

Compression:

Stored size: 810 Bytes

Contents

module EsSearchable
	module Configurable
		def self.extended(base)
			base.const_set :SearchMethods,
				[:where, :like, :limit, :offset, :or, :not, :select, :and]
			
			base.const_set :DEFAULTS, { 
				log: true,
				retry_on_failure: 5, 
				async_callback: true,
				queue: 'elasticsearch',
				reload_on_failure: true, 
				hosts: ['localhost:9200'], 
				logger: defined?(Rails) ? Logger.new($stdout) : nil,
			}
				
			base.class_eval do
				DEFAULTS.each do |k, v|
					self.define_singleton_method "#{k}=" do |value|
						self.options.merge!(k => value)
					end

					self.define_singleton_method k do
						self.options[k]
					end
				end
			end
		end

		def configure
			yield self
		end

		def options
			@options ||= DEFAULTS.dup
		end

		def options=(opts)
			@options = opts
		end

	end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
es_searchable-0.2.0 lib/es_searchable/configurable.rb
es_searchable-0.1.1 lib/es_searchable/configurable.rb