Class: Glossarist::ResolutionAdapter::Remote

Inherits:
Glossarist::ResolutionAdapter show all
Defined in:
lib/glossarist/resolution_adapter/remote.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#cacheObject (readonly)

Returns the value of attribute cache.



9
10
11
# File 'lib/glossarist/resolution_adapter/remote.rb', line 9

def cache
  @cache
end

#endpointObject (readonly)

Returns the value of attribute endpoint.



9
10
11
# File 'lib/glossarist/resolution_adapter/remote.rb', line 9

def endpoint
  @endpoint
end

#uri_prefixObject (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