Class: Gonzales::Collection
- Inherits:
-
Object
- Object
- Gonzales::Collection
- Defined in:
- lib/gonzales/collection.rb
Overview
Gonzales::Collection
Holds references to the factories instantiated during db:test:prepare
Class Method Summary collapse
-
.add(name, object) ⇒ Object
Adds an object (entity) to the collection.
-
.clear_cache ⇒ Object
Clears the cache of objects collected from load or instantiation.
-
.entities ⇒ Object
Retrieves the collection of entities.
-
.entity(factory_name) ⇒ Object
Retrieves a specific object.
-
.save ⇒ Object
Save a collection map to temporary file.
Class Method Details
.add(name, object) ⇒ Object
Adds an object (entity) to the collection.
32 33 34 35 |
# File 'lib/gonzales/collection.rb', line 32 def add(name, object) entities[name] = { :class => object.class.to_s, :id => object.id } object end |
.clear_cache ⇒ Object
Clears the cache of objects collected from load or instantiation
58 59 60 |
# File 'lib/gonzales/collection.rb', line 58 def clear_cache @@entities = {} end |
.entities ⇒ Object
Retrieves the collection of entities. If they are not already loded from the temporary cache map, the map is loaded.
39 40 41 |
# File 'lib/gonzales/collection.rb', line 39 def entities @@entities ||= load end |
.entity(factory_name) ⇒ Object
Retrieves a specific object
44 45 46 47 48 |
# File 'lib/gonzales/collection.rb', line 44 def entity(factory_name) if e = entities[factory_name] e[:class].constantize.find e[:id] end end |
.save ⇒ Object
Save a collection map to temporary file
51 52 53 54 55 |
# File 'lib/gonzales/collection.rb', line 51 def save #:nodoc: File.open(cache_filename, "w+") do |file| file.write entities.to_yaml end end |