class Qa::LDF::NamespacedSearchService
A search service that wraps another SearchService and casts its ids to a namespace.
@example
nsify = Qa::LDF::NamespacedSearchService.new do |service| service.namespace = 'http://example.com/ns/' service.parent_service = a_search_service_instance end # when a_search_service_endpoint.search('moomin') # => { 'id' => 'blah' } # then nsify.search('moomin') # => { 'id' => 'http://example.com/ns/blah' }
Attributes
namespace[RW]
parent_service[RW]
Public Class Methods
new() { |self| ... }
click to toggle source
@yieldparam service [NamespacedSearchService] yields self
# File lib/qa/ldf/namespaced_search_service.rb, line 30 def initialize yield self end
Public Instance Methods
apply_namespace(id)
click to toggle source
# File lib/qa/ldf/namespaced_search_service.rb, line 50 def apply_namespace(id) return id if RDF::URI(id).valid? (RDF::URI(namespace) / id).to_s end
search(query)
click to toggle source
@see Qa::Authority::Base#search
# File lib/qa/ldf/namespaced_search_service.rb, line 36 def search(query) responses = parent_service.search(query) responses.map do |result| if result.keys.first.is_a?(Symbol) result[:id] = apply_namespace(result[:id]) else result['id'] = apply_namespace(result['id']) end result end end