Class: AppEngine::PStore
- Inherits:
-
Object
- Object
- AppEngine::PStore
- Defined in:
- lib/appengine-pstore.rb
Instance Method Summary collapse
- #[](name) ⇒ Object
- #[]=(name, value) ⇒ Object
- #delete(name) ⇒ Object
- #dump(content) ⇒ Object
-
#initialize(dbname) ⇒ PStore
constructor
A new instance of PStore.
- #load(content) ⇒ Object
- #path ⇒ Object
- #root?(key) ⇒ Boolean
- #roots ⇒ Object
- #transaction(readonly = false) {|_self| ... } ⇒ Object
Constructor Details
Instance Method Details
#[](name) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/appengine-pstore.rb', line 46 def [](name) in_transaction raise PStore::Error, "in read-only transaction" if @rdonly if @cache.key?(name) @cache[name] # return latest put data else key = AppEngine::Datastore::Key.from_path(@parent_key, @kind, name) entity = AppEngine::Datastore.get(@transaction, key) load(entity[:value]) end end |
#[]=(name, value) ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/appengine-pstore.rb', line 58 def []=(name, value) in_transaction_wr entity = AppEngine::Datastore::Entity.new(@kind, name, @parent_key) entity[:value] = dump(value) AppEngine::Datastore.put(@transaction, entity) @cache[name] = value value end |
#delete(name) ⇒ Object
67 68 69 70 71 |
# File 'lib/appengine-pstore.rb', line 67 def delete(name) key = AppEngine::Datastore::Key.from_path(@parent_key, @kind, name) AppEngine::Datastore.delete(@transaction, key) @cache.delete(name) end |
#dump(content) ⇒ Object
77 78 79 |
# File 'lib/appengine-pstore.rb', line 77 def dump(content) Marshal::dump(content) end |
#load(content) ⇒ Object
73 74 75 |
# File 'lib/appengine-pstore.rb', line 73 def load(content) Marshal::load(content) end |
#path ⇒ Object
93 94 95 |
# File 'lib/appengine-pstore.rb', line 93 def path @parent_key end |
#root?(key) ⇒ Boolean
89 90 91 |
# File 'lib/appengine-pstore.rb', line 89 def root?(key) in_transaction end |