Class: Kayvee::Store

Inherits:
Object
  • Object
show all
Defined in:
lib/kayvee/store.rb

Overview

Represents a simple key value store. Provides multiple backing stores.

Examples:

Basic Useage

store = Kayvee::Store.new(:s3, aws_access_key: '', ... )
key = store.set('hello', 'world')
key.read
  => 'world'

store = Kayvee::Store.new(:redis, host: 'redis://locahost')
key = store.set('hello', 'world')
key.read
  => 'world'

See Also:

Constant Summary collapse

ClientNotFound =

Raised when a client implementation can not be found.

Class.new(Exception)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client = :s3, options = {}) ⇒ Store

Returns a new instance of Store.

Parameters:

  • client (Symbol) (defaults to: :s3)

    the symbol representing the client to use. :s3, :redis, :memory, :test

  • options (Options) (defaults to: {})

    the config for the client implementation

See Also:



33
34
35
36
# File 'lib/kayvee/store.rb', line 33

def initialize(client = :s3, options = {})
  load_client(client)
  @client = instantiate_client(client, options)
end

Instance Attribute Details

#clientObject (readonly)

The internal client driving the store



24
25
26
# File 'lib/kayvee/store.rb', line 24

def client
  @client
end

Instance Method Details

#clearObject

Clear the underlying store



62
63
64
# File 'lib/kayvee/store.rb', line 62

def clear
  @client.clear
end

#get(path) ⇒ Key Also known as: []

Gets a given keys value

Parameters:

  • path (String)

    the path to set

Returns:

  • (Key)

    the value of the key



56
57
58
# File 'lib/kayvee/store.rb', line 56

def get(path)
  Kayvee::Key.new(@client, path)
end

#set(path, value) ⇒ Key Also known as: []=

Sets a given key to a given value

Parameters:

  • path (String)

    the path to set

  • value (String)

    the value to set

Returns:

  • (Key)

    the newly created or modified key object



44
45
46
47
48
# File 'lib/kayvee/store.rb', line 44

def set(path, value)
  key = Kayvee::Key.new(@client, path)
  key.write(value)
  key
end

#sizeObject



66
67
68
# File 'lib/kayvee/store.rb', line 66

def size
  @client.size
end