Class: Lutaml::Model::Store

Inherits:
Object
  • Object
show all
Defined in:
lib/lutaml/model/store.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStore

Returns a new instance of Store.



32
33
34
# File 'lib/lutaml/model/store.rb', line 32

def initialize
  @store = ::Hash.new { |hash, key| hash[key] = [] }
end

Class Method Details

.clearObject



23
24
25
# File 'lib/lutaml/model/store.rb', line 23

def clear
  instance.clear
end

.instanceObject



7
8
9
# File 'lib/lutaml/model/store.rb', line 7

def instance
  @instance ||= new
end

.register(object) ⇒ Object



15
16
17
# File 'lib/lutaml/model/store.rb', line 15

def register(object)
  instance.register(object)
end

.reset!Object



11
12
13
# File 'lib/lutaml/model/store.rb', line 11

def reset!
  @instance = new
end

.resolve(model_class, reference_key, reference_value) ⇒ Object



19
20
21
# File 'lib/lutaml/model/store.rb', line 19

def resolve(model_class, reference_key, reference_value)
  instance.resolve(model_class, reference_key, reference_value)
end

.storeObject



27
28
29
# File 'lib/lutaml/model/store.rb', line 27

def store
  instance.store
end

Instance Method Details

#clearObject



50
51
52
# File 'lib/lutaml/model/store.rb', line 50

def clear
  @store = ::Hash.new { |hash, key| hash[key] = [] }
end

#register(object) ⇒ Object



36
37
38
39
40
# File 'lib/lutaml/model/store.rb', line 36

def register(object)
  model_class = object.class.to_s

  @store[model_class] << object
end

#resolve(model_class, reference_key, reference_value) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/lutaml/model/store.rb', line 42

def resolve(model_class, reference_key, reference_value)
  return nil unless @store[model_class.to_s]

  @store[model_class.to_s].find do |obj|
    obj.send(reference_key) == reference_value
  end
end

#storeObject



54
55
56
# File 'lib/lutaml/model/store.rb', line 54

def store
  @store
end