Class: Qa::LDF::NamespacedSearchService
- Inherits:
-
Object
- Object
- Qa::LDF::NamespacedSearchService
show all
- Defined in:
- lib/qa/ldf/namespaced_search_service.rb
Overview
A search service that wraps another SearchService and casts its ids to a
namespace.
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of NamespacedSearchService.
30
31
32
|
# File 'lib/qa/ldf/namespaced_search_service.rb', line 30
def initialize
yield self
end
|
Instance Attribute Details
#namespace ⇒ String
26
27
28
|
# File 'lib/qa/ldf/namespaced_search_service.rb', line 26
def namespace
@namespace
end
|
#parent_service ⇒ #search
26
|
# File 'lib/qa/ldf/namespaced_search_service.rb', line 26
attr_accessor :namespace, :parent_service
|
Instance Method Details
#apply_namespace(id) ⇒ Object
50
51
52
53
|
# 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) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# 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
|