Class: Vorpal::LoadedObjects

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable, Util::ArrayHash
Defined in:
lib/vorpal/loaded_objects.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util::ArrayHash

#add_to_hash, #pop

Constructor Details

#initializeLoadedObjects

Returns a new instance of LoadedObjects.



15
16
17
18
# File 'lib/vorpal/loaded_objects.rb', line 15

def initialize
  @objects = Hash.new([])
  @objects_by_id = Hash.new
end

Instance Attribute Details

#objectsObject (readonly)

Returns the value of attribute objects.



12
13
14
# File 'lib/vorpal/loaded_objects.rb', line 12

def objects
  @objects
end

Instance Method Details

#add(config, objects) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/vorpal/loaded_objects.rb', line 20

def add(config, objects)
  objects_to_add = objects.map do |object|
    if !already_loaded?(config, object.id)
      @objects_by_id[[config.domain_class.name, object.id]] = object
    end
  end
  add_to_hash(@objects, config, objects_to_add.compact)
end

#all_objectsObject



33
34
35
# File 'lib/vorpal/loaded_objects.rb', line 33

def all_objects
  @objects_by_id.values
end

#already_loaded?(config, id) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/vorpal/loaded_objects.rb', line 37

def already_loaded?(config, id)
  !find_by_id(config, id).nil?
end

#find_by_id(config, id) ⇒ Object



29
30
31
# File 'lib/vorpal/loaded_objects.rb', line 29

def find_by_id(config, id)
  @objects_by_id[[config.domain_class.name, id]]
end