Class: FWToolkit::Test::FrankCache
- Inherits:
-
Object
- Object
- FWToolkit::Test::FrankCache
- Defined in:
- lib/fwtoolkit/test/frank_model.rb
Constant Summary collapse
- @@klass_to_objects =
{}
- @@id_to_object =
{}
Class Method Summary collapse
- .add_object(object) ⇒ Object
- .all_objects(klass) ⇒ Object
- .clean_up ⇒ Object
- .find(id) ⇒ Object
- .find_all(klass, conditions) ⇒ Object
- .find_first(klass, conditions) ⇒ Object
Class Method Details
.add_object(object) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/fwtoolkit/test/frank_model.rb', line 14 def self.add_object(object) object.id = object.object_id # add to id to object hash @@id_to_object[object.object_id.to_s] = object # add to klass to object hash @@klass_to_objects[object.class.name] = [] unless @@klass_to_objects[object.class.name] @@klass_to_objects[object.class.name] << object end |
.all_objects(klass) ⇒ Object
25 26 27 |
# File 'lib/fwtoolkit/test/frank_model.rb', line 25 def self.all_objects(klass) @@klass_to_objects[klass.name] ? @@klass_to_objects[klass.name] : [] end |
.clean_up ⇒ Object
9 10 11 12 |
# File 'lib/fwtoolkit/test/frank_model.rb', line 9 def self.clean_up @@klass_to_objects = {} @@id_to_object = {} end |
.find(id) ⇒ Object
29 30 31 |
# File 'lib/fwtoolkit/test/frank_model.rb', line 29 def self.find(id) @@id_to_object[id.to_s] end |
.find_all(klass, conditions) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/fwtoolkit/test/frank_model.rb', line 37 def self.find_all(klass, conditions) objects = [] FWToolkit::Test::FrankCache.all_objects(klass).each do |o| match = true conditions.keys.each do |k| if not eval("o.#{k}").eql? conditions[k] match = false break end end objects << o if match end objects end |
.find_first(klass, conditions) ⇒ Object
33 34 35 |
# File 'lib/fwtoolkit/test/frank_model.rb', line 33 def self.find_first(klass, conditions) self.find_all(klass, conditions).first end |