Class: Qa::LDF::Authority
- Inherits:
-
Authorities::Base
- Object
- Authorities::Base
- Qa::LDF::Authority
- Defined in:
- lib/qa/ldf/authority.rb
Overview
A Linked Data Fragments-based authority. Access linked data resources through a caching server.
Constant Summary collapse
- DEFAULT_DATASET_NAME =
The default linked data fragments client
:''
- DEFAULT_CLIENT =
The default linked data fragments client
Qa::LDF::Client
- DEFAULT_MAPPER =
The default mapper
Qa::LDF::JsonMapper
- DEFAULT_SEARCH_SERVICE =
The default search service
Qa::LDF::EmptySearchService
- @@namespace_map =
{}
Instance Attribute Summary collapse
Class Method Summary collapse
-
.for(namespace:) ⇒ Authority
Gives an authority class for the given namespace.
-
.namespace ⇒ String
Gives an empty string for no namespace, #for_namespace returns self in this case.
- .namespaces ⇒ Enumerable<String>
-
.register_namespace(namespace:, klass:)
Registers a namespace/class pair.
-
.reset_namespaces
Resets the namespaces.
Instance Method Summary collapse
- #all ⇒ Object
-
#find(id) ⇒ Object
Retrieves the given resource's JSON respresentation from the cache server.
- #graph(uri) ⇒ RDF::Enumerable
-
#initialize {|authority| ... } ⇒ Authority
constructor
A new instance of Authority.
-
#search(query) ⇒ Array<Hash<Symbol, String>>
Search the vocabulary.
Constructor Details
#initialize {|authority| ... } ⇒ Authority
Returns a new instance of Authority.
88 89 90 91 |
# File 'lib/qa/ldf/authority.rb', line 88 def initialize(*) super yield self if block_given? end |
Instance Attribute Details
#client ⇒ Qa::LDF::Client
84 |
# File 'lib/qa/ldf/authority.rb', line 84 attr_writer :client, :dataset, :mapper, :search_service |
#dataset ⇒ Symbol
84 |
# File 'lib/qa/ldf/authority.rb', line 84 attr_writer :client, :dataset, :mapper, :search_service |
#mapper ⇒ JsonMapper
84 |
# File 'lib/qa/ldf/authority.rb', line 84 attr_writer :client, :dataset, :mapper, :search_service |
#search_service ⇒ #search
84 |
# File 'lib/qa/ldf/authority.rb', line 84 attr_writer :client, :dataset, :mapper, :search_service |
Class Method Details
.for(namespace:) ⇒ Authority
Gives an authority class for the given namespace.
38 39 40 |
# File 'lib/qa/ldf/authority.rb', line 38 def for(namespace:) @@namespace_map.fetch(namespace.to_s) { self }.new end |
.namespace ⇒ String
Returns gives an empty string for no namespace, #for_namespace returns self in this case.
45 46 47 |
# File 'lib/qa/ldf/authority.rb', line 45 def namespace '' end |
.namespaces ⇒ Enumerable<String>
51 52 53 |
# File 'lib/qa/ldf/authority.rb', line 51 def namespaces @@namespace_map.keys end |
.register_namespace(namespace:, klass:)
This method returns an undefined value.
Registers a namespace/class pair.
62 63 64 |
# File 'lib/qa/ldf/authority.rb', line 62 def register_namespace(namespace:, klass:) @@namespace_map[namespace.to_s] = klass end |
.reset_namespaces
This method returns an undefined value.
Resets the namespaces
70 71 72 |
# File 'lib/qa/ldf/authority.rb', line 70 def reset_namespaces @@namespace_map = {} end |
Instance Method Details
#all ⇒ Object
95 96 97 |
# File 'lib/qa/ldf/authority.rb', line 95 def all [] end |
#find(id) ⇒ Object
Retrieves the given resource's JSON respresentation from the cache server.
The resource is retrieved through the client given by #client
, and
mapped to JSON using #mapper
.
108 109 110 |
# File 'lib/qa/ldf/authority.rb', line 108 def find(id) mapper.map_resource(id, graph(id)) end |
#graph(uri) ⇒ RDF::Enumerable
115 116 117 |
# File 'lib/qa/ldf/authority.rb', line 115 def graph(uri) client.get(uri: uri, dataset: dataset) end |
#search(query) ⇒ Array<Hash<Symbol, String>>
Search the vocabulary
126 127 128 |
# File 'lib/qa/ldf/authority.rb', line 126 def search(query) search_service.search(query) end |