Class: Mince::HashyDb::DataStore
- Inherits:
-
Object
- Object
- Mince::HashyDb::DataStore
- 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
Instance Attribute Summary collapse
-
#data ⇒ Hash
The attribute containing the data.
Class Method Summary collapse
-
.collection(collection_name) ⇒ Array
The collection in the data store.
-
.data ⇒ Hash
Class level access to the in-memory data store.
-
.set_data(hash) ⇒ Object
Sets the entire data store, for all collections.
Instance Method Summary collapse
-
#initialize ⇒ DataStore
constructor
A new instance of DataStore.
Constructor Details
#initialize ⇒ DataStore
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
#data ⇒ Hash
The attribute containing the data
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
41 42 43 |
# File 'lib/hashy_db/data_store.rb', line 41 def self.collection(collection_name) data[collection_name] ||= [] end |
.data ⇒ Hash
Class level access to the in-memory data store
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
26 27 28 |
# File 'lib/hashy_db/data_store.rb', line 26 def self.set_data(hash) instance.data = hash end |