Module: QuickStore
- Defined in:
- lib/quick_store.rb,
lib/quick_store/store.rb,
lib/quick_store/version.rb,
lib/quick_store/configuration.rb
Overview
Allows configuring a YAML store and accessing the configured YAML store through the .store method.
Defined Under Namespace
Classes: Configuration, Store
Constant Summary collapse
- NO_FILE_PATH_CONFIGURED =
'Please configure a file_path for your QuickStore!'.freeze
- VERSION =
'0.2.0'.freeze
Class Attribute Summary collapse
-
.configuration ⇒ Object
Returns the value of attribute configuration.
Class Method Summary collapse
-
.config ⇒ Object
Returns the QuickStore::Configuration.
-
.configure {|config| ... } ⇒ Object
Configures the QuickStore::Store.
-
.store ⇒ Object
Returns the QuickStore::Store.
Class Attribute Details
.configuration ⇒ Object
Returns the value of attribute configuration.
11 12 13 |
# File 'lib/quick_store.rb', line 11 def configuration @configuration end |
Class Method Details
.config ⇒ Object
Returns the QuickStore::Configuration.
27 28 29 |
# File 'lib/quick_store.rb', line 27 def self.config self.configuration ||= Configuration.new end |
.configure {|config| ... } ⇒ Object
Configures the QuickStore::Store
QuickStore.configure do |config|
config.file_path = 'path/to/store/file.yml'
config.key_separator = '|' # default is '/'
end
20 21 22 23 24 |
# File 'lib/quick_store.rb', line 20 def self.configure yield(config) if block_given? raise(NO_FILE_PATH_CONFIGURED) unless config.file_path config end |
.store ⇒ Object
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"}}
47 48 49 |
# File 'lib/quick_store.rb', line 47 def self.store QuickStore::Store end |