Class: ODB::DataStore
Instance Attribute Summary collapse
-
#db ⇒ Object
Returns the value of attribute db.
-
#key_cache ⇒ Object
readonly
Returns the value of attribute key_cache.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #after_commit ⇒ Object
-
#initialize(name) ⇒ DataStore
constructor
A new instance of DataStore.
- #read(key) ⇒ Object
- #write(key, value) ⇒ Object
Constructor Details
#initialize(name) ⇒ DataStore
Returns a new instance of DataStore.
34 35 36 37 38 |
# File 'lib/odb.rb', line 34 def initialize(name) @name = name @key_cache = {} @object_map = {} end |
Instance Attribute Details
#db ⇒ Object
Returns the value of attribute db.
32 33 34 |
# File 'lib/odb.rb', line 32 def db @db end |
#key_cache ⇒ Object (readonly)
Returns the value of attribute key_cache.
31 32 33 |
# File 'lib/odb.rb', line 31 def key_cache @key_cache end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
31 32 33 |
# File 'lib/odb.rb', line 31 def name @name end |
Instance Method Details
#[](key) ⇒ Object
61 |
# File 'lib/odb.rb', line 61 def [](key) read(key) end |
#[]=(key, value) ⇒ Object
62 |
# File 'lib/odb.rb', line 62 def []=(key, value) write(key, value) end |
#after_commit ⇒ Object
64 |
# File 'lib/odb.rb', line 64 def after_commit; end |
#read(key) ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/odb.rb', line 40 def read(key) key = key_cache[key] if Symbol === key if oid = @object_map[key] ObjectSpace._id2ref(oid) else obj = read_object(key) @object_map[key] = obj.object_id obj end end |
#write(key, value) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/odb.rb', line 51 def write(key, value) if Symbol === key key = (key_cache[key] = value.object_id) @object_map[key] = value.object_id return end @object_map[key] = value.object_id write_object(key, value) end |