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 34 def initialize(client, options = client.options) 35 @client, @endpoints = client, [] 36 register(options.fetch(:endpoints, DEFAULT_ENDPOINTS)) 37 end
Public Instance Methods
inspect()
click to toggle source
# File lib/solr4r/endpoints.rb 71 def inspect 72 '#<%s:0x%x [%s]>' % [self.class, object_id, 73 @endpoints.map { |ep| ep.uniq.join('=') }.join(', ')] 74 end
register(path, options = {})
click to toggle source
# File lib/solr4r/endpoints.rb 41 def register(path, options = {}) 42 case path 43 when nil 44 # ignore 45 when Symbol 46 register(path.to_s, options) 47 when Array 48 path.each { |args| register(*args) } 49 when Hash 50 path.each { |_path, _options| register(_path, 51 _options.is_a?(Hash) ? _options : { path: _options }) } 52 when String 53 name, path = File.basename(path), options.fetch(:path, path).to_s 54 55 error = invalid_endpoint?(name) and 56 raise ArgumentError, "invalid endpoint: #{name} (#{error})" 57 58 @endpoints << [name, path] 59 60 define_singleton_method(name) { |_params = {}, _options = {}, &block| 61 client.send(:send_request, path, options.merge(_options.merge( 62 params: options.fetch(:params, {}).merge(_params))), &block) 63 } 64 else 65 raise TypeError, "unexpected type #{path.class}" 66 end 67 68 self 69 end
Private Instance Methods
invalid_endpoint?(name)
click to toggle source
# File lib/solr4r/endpoints.rb 78 def invalid_endpoint?(name) 79 'method already defined' if respond_to?(name) || ( 80 respond_to?(name, true) && 81 DEFAULT_ENDPOINTS.all? { |ep,| ep.to_s != name }) 82 end