Class: ReferencesCache

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/javonet-ruby-sdk/core/reference_cache/references_cache.rb,
lib/javonet-ruby-sdk/Binaries/Ruby/Linux/X64/core/reference_cache/references_cache.rb,
lib/javonet-ruby-sdk/Binaries/Ruby/MacOs/X64/core/reference_cache/references_cache.rb,
lib/javonet-ruby-sdk/Binaries/Ruby/Windows/X64/core/reference_cache/references_cache.rb

Constant Summary

Constants included from Singleton

Singleton::VERSION

Instance Method Summary collapse

Methods included from Singleton

__init__, #_dump, #clone, #dup

Constructor Details

#initializeReferencesCache

Returns a new instance of ReferencesCache.



7
8
9
# File 'lib/javonet-ruby-sdk/core/reference_cache/references_cache.rb', line 7

def initialize
  @references_cache = Hash.new
end

Instance Method Details

#cache_reference(object_reference) ⇒ Object



11
12
13
14
15
# File 'lib/javonet-ruby-sdk/core/reference_cache/references_cache.rb', line 11

def cache_reference(object_reference)
  uuid_ = SecureRandom.uuid
  @references_cache[uuid_] = object_reference
  uuid_
end

#delete_reference(guid) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/javonet-ruby-sdk/core/reference_cache/references_cache.rb', line 25

def delete_reference(guid)
  if @references_cache[guid].nil?
    raise 'Object not found in reference cache'
  else
    @references_cache.delete(guid)
    0
  end
end

#resolve_reference(guid) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/javonet-ruby-sdk/core/reference_cache/references_cache.rb', line 17

def resolve_reference(guid)
  if @references_cache[guid].nil?
    raise 'Unable to resolve reference with id: ' + guid.to_s
  else
    @references_cache[guid]
  end
end