Module: QuickStore

Defined in:
lib/quick_store.rb,
lib/quick_store/store.rb,
lib/quick_store/version.rb

Defined Under Namespace

Classes: Configuration, Store

Constant Summary collapse

NO_FILE_PATH_CONFIGURED =
"Please configure a file_path for your QuickStore!"
VERSION =
"0.1.0"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject

Returns the value of attribute configuration.



9
10
11
# File 'lib/quick_store.rb', line 9

def configuration
  @configuration
end

Class Method Details

.configObject

Returns the QuickStore::Configuration.



25
26
27
# File 'lib/quick_store.rb', line 25

def self.config
  self.configuration ||= Configuration.new
end

.configure {|self.config| ... } ⇒ Object

Configures the QuickStore::Store

QuickStore.configure do |config|
config.file_path = 'path/to/store/file.yml'
config.key_separator = '|' # default is '/'
end

Yields:

Raises:



18
19
20
21
22
# File 'lib/quick_store.rb', line 18

def self.configure
  yield(self.config)
  raise(NO_FILE_PATH_CONFIGURED) unless self.config.file_path
  self.config
end

.storeObject

Returns the QuickStore::Store. You can store and receive data from the store using different methods:

Using dynamic setters and getters

QuickStore.store.arbitrary_key = 'value' # => "value" QuickStore.store.arbitrary_key # => "value"

Using the ::set and ::get methods

QuickStore.store.set(:arbitrary_key, 'value') # => "value" QuickStore.store.get(:arbitrary_key) # => "value"

Example for a nested key ('/' is the default key separator)

QuickStore.store.set('a/b/c', 'value') # => "b"=>{"c"=>"value"} QuickStore.store.get('a/b/c') # => "value" QuickStore.store.get('a/b') # => "c"=>"value" QuickStore.store.get('a') # => "b"=>{"c"=>"value"}



45
46
47
# File 'lib/quick_store.rb', line 45

def self.store
  QuickStore::Store
end