Class: Mince::HashyDb::DataStore

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/hashy_db/data_store.rb

Overview

HashyDb Data Store

HashyDb Data Store stores and retrieves data from a ruby in-memory hash.

Using this library offers more extensibility and growth for your application. If at any point in time you want to support a different database for all, or even one, of your classes, you only need to implement the few methods defined in this class.

HashyDb Data Store is a singleton object that provides class level interface to the singleton instance.

Mince::HashyDb::DataStore.instance # => Mince::HashyDb::DataStore object
Mince::HashyDb::DataStore.data # => returns all data stored in the HashyDb database
Mince::HashyDb::DataStore.collection(:some_collection) # => returns all data stored in a specific collection in the HashyDb database

Author:

  • Matt Simpson

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDataStore

Returns a new instance of DataStore.



50
51
52
# File 'lib/hashy_db/data_store.rb', line 50

def initialize
  @data = {}
end

Instance Attribute Details

#dataHash

The attribute containing the data

Returns:

  • (Hash)

    all collections along with the contents of each collection, defaults to an empty hash



48
49
50
# File 'lib/hashy_db/data_store.rb', line 48

def data
  @data
end

Class Method Details

.collection(collection_name) ⇒ Array

The collection in the data store

Parameters:

  • collection_name (Symbol)

    the name of the collection

Returns:

  • (Array)

    all records in the collection, defaults to an empty array



41
42
43
# File 'lib/hashy_db/data_store.rb', line 41

def self.collection(collection_name)
  data[collection_name] ||= []
end

.dataHash

Class level access to the in-memory data store

Returns:

  • (Hash)

    all collections along with the contents of each collection



33
34
35
# File 'lib/hashy_db/data_store.rb', line 33

def self.data
  instance.data
end

.set_data(hash) ⇒ Object

Sets the entire data store, for all collections

Parameters:

  • hash (Hash)

    the hash to replace the entire data store with



26
27
28
# File 'lib/hashy_db/data_store.rb', line 26

def self.set_data(hash)
  instance.data = hash
end