QuickStore
Simple local key-value store based on YAML::Store.
Installation
Add this line to your application's Gemfile:
gem 'quick_store'
And then execute:
$ bundle
Or install it yourself as:
$ gem install quick_store
Usage
require 'quick_store'
Configuration
QuickStore.configure do |config|
config.file_path = 'path/to/store/file.yml'
config.key_separator = '|' # default is '/'
end
Storing, fetching, and deleting data
You can store, receive, and remove data from the store by using different methods:
# Using dynamic setters and getters
QuickStore.store.arbitrary_key = 'value' # => "value"
QuickStore.store.arbitrary_key # => "value"
QuickStore.store.delete_arbitrary_key # => "value"
# Using the ::set, ::get, and ::delete methods
QuickStore.store.set(:arbitrary_key, 'value') # => "value"
QuickStore.store.get(:arbitrary_key) # => "value"
QuickStore.store.delete(: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"}}
# Removing data for a certain nested key
QuickStore.store.delete('a/b/c') # => {"b"=>{"c"=>nil}}
QuickStore.store.get('a') # => {"b"=>{"c"=>nil}}
# Removing data for all nested keys under a certain key
QuickStore.store.delete('a') # => {"b"=>{"c"=>nil}}
QuickStore.store.get('a') # => nil
Contributing
- Fork it ( https://github.com/[my-github-username]/quick_store/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
License
The quick_store gem is released under the MIT License.