Class: TDriver::TestObjectCache
- Defined in:
- lib/tdriver/base/test_object/cache.rb
Overview
TODO: document me
Instance Method Summary collapse
-
#[](value) ⇒ Object
TODO: document me.
-
#add_object(test_object) ⇒ Object
TODO: document me.
-
#each_object(&block) ⇒ Object
TODO: document me.
-
#has_object?(test_object) ⇒ Boolean
TODO: document me.
-
#initialize ⇒ TestObjectCache
constructor
TODO: document me.
-
#object_keys ⇒ Object
TODO: document me.
-
#object_values ⇒ Object
TODO: document me.
-
#objects ⇒ Object
TODO: document me.
-
#remove_object(test_object) ⇒ Object
TODO: document me.
-
#remove_objects ⇒ Object
TODO: document me.
Constructor Details
#initialize ⇒ TestObjectCache
TODO: document me
27 28 29 30 31 |
# File 'lib/tdriver/base/test_object/cache.rb', line 27 def initialize() @objects = {} end |
Instance Method Details
#[](value) ⇒ Object
TODO: document me
78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/tdriver/base/test_object/cache.rb', line 78 def []( value ) if value.kind_of?( Numeric ) @objects.fetch( value ){ raise ArgumentError, "Test object (#{ value }) not found from cache" } else @objects.fetch( value.hash ){ raise ArgumentError, "Test object (#{ value.hash }) not found from cache" } end end |
#add_object(test_object) ⇒ Object
TODO: document me
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/tdriver/base/test_object/cache.rb', line 93 def add_object( test_object ) test_object_hash = test_object.hash if @objects.has_key?( test_object_hash ) warn( "warning: Test object (#{ test_object_hash }) already exists in cache" ) end @objects[ test_object_hash ] = test_object test_object end |
#each_object(&block) ⇒ Object
TODO: document me
34 35 36 37 38 |
# File 'lib/tdriver/base/test_object/cache.rb', line 34 def each_object( &block ) @objects.each_value{ | object | yield( object ) } end |
#has_object?(test_object) ⇒ Boolean
TODO: document me
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/tdriver/base/test_object/cache.rb', line 48 def has_object?( test_object ) if test_object.kind_of?( Numeric ) @objects.has_key?( test_object ) else @objects.has_key?( test_object.hash ) end end |
#object_keys ⇒ Object
TODO: document me
64 65 66 67 68 |
# File 'lib/tdriver/base/test_object/cache.rb', line 64 def object_keys @objects.keys end |
#object_values ⇒ Object
TODO: document me
71 72 73 74 75 |
# File 'lib/tdriver/base/test_object/cache.rb', line 71 def object_values @objects.values end |
#objects ⇒ Object
TODO: document me
41 42 43 44 45 |
# File 'lib/tdriver/base/test_object/cache.rb', line 41 def objects @objects end |
#remove_object(test_object) ⇒ Object
TODO: document me
110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/tdriver/base/test_object/cache.rb', line 110 def remove_object( test_object ) test_object_hash = test_object.hash @objects.delete( test_object_hash ) #raise ArgumentError, "Test object (#{ test_object_hash }) not found from cache" unless @objects.has_key?( test_object_hash ) self end |
#remove_objects ⇒ Object
TODO: document me
123 124 125 126 127 |
# File 'lib/tdriver/base/test_object/cache.rb', line 123 def remove_objects @objects.clear end |