Class: Vorpal::LoadedObjects
- Inherits:
-
Object
- Object
- Vorpal::LoadedObjects
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/vorpal/loaded_objects.rb
Instance Method Summary collapse
- #add(config, objects) ⇒ Object
- #all_objects ⇒ Object
- #already_loaded_by_unique_key?(config, column_name, id) ⇒ Boolean
- #find_by_primary_key(config, object) ⇒ Object
- #find_by_unique_key(config, column_name, value) ⇒ Object
-
#initialize ⇒ LoadedObjects
constructor
A new instance of LoadedObjects.
Constructor Details
#initialize ⇒ LoadedObjects
Returns a new instance of LoadedObjects.
13 14 15 16 |
# File 'lib/vorpal/loaded_objects.rb', line 13 def initialize @objects = Util::ArrayHash.new @cache = {} end |
Instance Method Details
#add(config, objects) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/vorpal/loaded_objects.rb', line 18 def add(config, objects) objects_to_add = objects.map do |object| if !already_loaded?(config, object) add_to_cache(config, object) end end.compact @objects.append(config, objects_to_add) objects_to_add end |
#all_objects ⇒ Object
36 37 38 |
# File 'lib/vorpal/loaded_objects.rb', line 36 def all_objects @objects.values end |
#already_loaded_by_unique_key?(config, column_name, id) ⇒ Boolean
40 41 42 |
# File 'lib/vorpal/loaded_objects.rb', line 40 def already_loaded_by_unique_key?(config, column_name, id) !find_by_unique_key(config, column_name, id).nil? end |
#find_by_primary_key(config, object) ⇒ Object
28 29 30 |
# File 'lib/vorpal/loaded_objects.rb', line 28 def find_by_primary_key(config, object) find_by_unique_key(config, "id", object.id) end |
#find_by_unique_key(config, column_name, value) ⇒ Object
32 33 34 |
# File 'lib/vorpal/loaded_objects.rb', line 32 def find_by_unique_key(config, column_name, value) get_from_cache(config, column_name, value) end |