Class: ReferencesCache
- Inherits:
-
Object
- Object
- ReferencesCache
- Defined in:
- lib/javonet-ruby-sdk/core/reference_cache/references_cache.rb
Class Method Summary collapse
Instance Method Summary collapse
- #cache_reference(object_reference) ⇒ Object
- #delete_reference(guid) ⇒ Object
- #generate_uuid ⇒ Object
-
#initialize ⇒ ReferencesCache
constructor
A new instance of ReferencesCache.
- #resolve_reference(guid) ⇒ Object
Constructor Details
#initialize ⇒ ReferencesCache
Returns a new instance of ReferencesCache.
9 10 11 |
# File 'lib/javonet-ruby-sdk/core/reference_cache/references_cache.rb', line 9 def initialize @references_cache = {} end |
Class Method Details
.instance ⇒ Object
5 6 7 |
# File 'lib/javonet-ruby-sdk/core/reference_cache/references_cache.rb', line 5 def self.instance @instance ||= new end |
Instance Method Details
#cache_reference(object_reference) ⇒ Object
13 14 15 16 17 |
# File 'lib/javonet-ruby-sdk/core/reference_cache/references_cache.rb', line 13 def cache_reference(object_reference) uuid_ = generate_uuid @references_cache[uuid_] = object_reference uuid_ end |
#delete_reference(guid) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/javonet-ruby-sdk/core/reference_cache/references_cache.rb', line 27 def delete_reference(guid) if @references_cache[guid].nil? raise 'Object not found in reference cache' else @references_cache.delete(guid) 0 end end |
#generate_uuid ⇒ Object
36 37 38 |
# File 'lib/javonet-ruby-sdk/core/reference_cache/references_cache.rb', line 36 def generate_uuid [8, 4, 4, 4, 12].map { |n| rand(16**n).to_s(16).rjust(n, '0') }.join('-') end |
#resolve_reference(guid) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/javonet-ruby-sdk/core/reference_cache/references_cache.rb', line 19 def resolve_reference(guid) if @references_cache[guid].nil? raise "Unable to resolve reference with id: #{guid}" else @references_cache[guid] end end |