class Geode::Store

Subclass this to implement your own stores.

Public Class Methods

new(name, connection = nil) click to toggle source

Connect to a store. @param name [Symbol, String] The name of the store @param connection [Hash, String] Connection parameters passed to the DB client

# File lib/geode.rb, line 7
def initialize(name, connection = nil)
  @name = name.to_s
end

Public Instance Methods

[](key) click to toggle source

Retrieve the object at `key` from the store. This is implemented using `#peek` and therefore changes to the object returned by this method will NOT be persisted in the store. Use this if you simply need to fetch a value from the store. @example

"store[:key] #=> 5"

@param key [Object] The key to look up @return [Object] The object at `key`

# File lib/geode.rb, line 44
def [](key)
  peek[key]
end
destroy() click to toggle source

“Destroy” the store, deleting all data. The store can be opened again, recreating it in a blank state.

# File lib/geode.rb, line 50
def destroy
  raise 'subclasses must implement #destroy'
end
open() click to toggle source

“Open” the store for reading and/or writing. @yield a block which receives `table` as its sole parameter @yieldparam table [Hash] The store's table. Changes to this Hash will be persisted in the store When in doubt, use this method. @example

"store.open { |table| table[:key] = 5 }"

@example

"store.open { |table| table[:key] } #=> 5"

@return [Object] The return value of the block

# File lib/geode.rb, line 21
def open
  raise 'subclasses must implement #open'
end
peek() click to toggle source

“Peek” inside the store, returning a copy of its table. Changes to this copy will NOT be persisted in the store. Use this if you simply want to view the store's table. @example

"store.peek.key?(:test) #=> false"

@return [Hash] A copy of the store's table

# File lib/geode.rb, line 31
def peek
  open(&:itself)
end