Class: TDriver::TestObjectCache

Inherits:
Object
  • Object
show all
Defined in:
lib/tdriver/base/test_object/cache.rb

Overview

TODO: document me

Instance Method Summary collapse

Constructor Details

#initializeTestObjectCache

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

Returns:

  • (Boolean)


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_keysObject

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_valuesObject

TODO: document me



71
72
73
74
75
# File 'lib/tdriver/base/test_object/cache.rb', line 71

def object_values

  @objects.values
    
end

#objectsObject

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_objectsObject

TODO: document me



123
124
125
126
127
# File 'lib/tdriver/base/test_object/cache.rb', line 123

def remove_objects

  @objects.clear

end