class Solr4R::Endpoints
Constants
- DEFAULT_ENDPOINTS
Attributes
client[R]
Public Class Methods
new(client, options = client.options)
click to toggle source
# File lib/solr4r/endpoints.rb, line 33 def initialize(client, options = client.options) @client, @endpoints = client, [] register(options.fetch(:endpoints, DEFAULT_ENDPOINTS)) end
Public Instance Methods
inspect()
click to toggle source
# File lib/solr4r/endpoints.rb, line 70 def inspect '#<%s:0x%x [%s]>' % [self.class, object_id, @endpoints.map { |ep| ep.uniq.join('=') }.join(', ')] end
register(path, options = {})
click to toggle source
# File lib/solr4r/endpoints.rb, line 40 def register(path, options = {}) case path when nil # ignore when Symbol register(path.to_s, options) when Array path.each { |args| register(*args) } when Hash path.each { |_path, _options| register(_path, _options.is_a?(Hash) ? _options : { path: _options }) } when String name, path = File.basename(path), options.fetch(:path, path).to_s error = invalid_endpoint?(name) and raise ArgumentError, "invalid endpoint: #{name} (#{error})" @endpoints << [name, path] define_singleton_method(name) { |_params = {}, _options = {}, &block| client.send(:send_request, path, options.merge(_options.merge( params: options.fetch(:params, {}).merge(_params))), &block) } else raise TypeError, "unexpected type #{path.class}" end self end
Private Instance Methods
invalid_endpoint?(name)
click to toggle source
# File lib/solr4r/endpoints.rb, line 77 def invalid_endpoint?(name) 'method already defined' if respond_to?(name) || ( respond_to?(name, true) && DEFAULT_ENDPOINTS.all? { |ep,| ep.to_s != name }) end