Class: Glossarist::ResolutionAdapter::Remote
- Inherits:
-
Glossarist::ResolutionAdapter
- Object
- Glossarist::ResolutionAdapter
- Glossarist::ResolutionAdapter::Remote
- Defined in:
- lib/glossarist/resolution_adapter/remote.rb
Instance Attribute Summary collapse
-
#cache ⇒ Object
readonly
Returns the value of attribute cache.
-
#endpoint ⇒ Object
readonly
Returns the value of attribute endpoint.
-
#uri_prefix ⇒ Object
readonly
Returns the value of attribute uri_prefix.
Instance Method Summary collapse
-
#initialize(uri_prefix:, endpoint:) ⇒ Remote
constructor
A new instance of Remote.
- #resolve(reference) ⇒ Object
Constructor Details
#initialize(uri_prefix:, endpoint:) ⇒ Remote
Returns a new instance of Remote.
11 12 13 14 15 16 |
# File 'lib/glossarist/resolution_adapter/remote.rb', line 11 def initialize(uri_prefix:, endpoint:) super() @uri_prefix = uri_prefix @endpoint = endpoint.chomp("/") @cache = {} end |
Instance Attribute Details
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
9 10 11 |
# File 'lib/glossarist/resolution_adapter/remote.rb', line 9 def cache @cache end |
#endpoint ⇒ Object (readonly)
Returns the value of attribute endpoint.
9 10 11 |
# File 'lib/glossarist/resolution_adapter/remote.rb', line 9 def endpoint @endpoint end |
#uri_prefix ⇒ Object (readonly)
Returns the value of attribute uri_prefix.
9 10 11 |
# File 'lib/glossarist/resolution_adapter/remote.rb', line 9 def uri_prefix @uri_prefix end |
Instance Method Details
#resolve(reference) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/glossarist/resolution_adapter/remote.rb', line 18 def resolve(reference) return nil unless reference.ref_type == "urn" return nil unless reference.source == uri_prefix key = cache_key(reference) return @cache[key] if @cache.key?(key) @cache[key] = fetch(reference) end |