Class: Vorpal::LoadedObjects
- Inherits:
-
Object
- Object
- Vorpal::LoadedObjects
- Extended by:
- Forwardable
- Includes:
- Enumerable, Util::ArrayHash
- Defined in:
- lib/vorpal/loaded_objects.rb
Instance Attribute Summary collapse
-
#objects ⇒ Object
readonly
Returns the value of attribute objects.
Instance Method Summary collapse
- #add(config, objects) ⇒ Object
- #all_objects ⇒ Object
- #already_loaded?(config, id) ⇒ Boolean
- #find_by_id(config, id) ⇒ Object
-
#initialize ⇒ LoadedObjects
constructor
A new instance of LoadedObjects.
Methods included from Util::ArrayHash
Constructor Details
#initialize ⇒ LoadedObjects
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
#objects ⇒ Object (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_objects ⇒ Object
33 34 35 |
# File 'lib/vorpal/loaded_objects.rb', line 33 def all_objects @objects_by_id.values end |
#already_loaded?(config, id) ⇒ 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 |