Store key-value pair-based objects in a key-based hierarchy. Provides a pluggable interface for multiple back-ends.
To install through Rubygems:
gem install teton
You can also add this to your Gemfile using:
bundle add teton
The main API is made up of these instance methods:
Method | Description |
---|---|
Db#set(key, data = {}) |
Set an entries data to the passed in values. |
Db#get(key, limit: nil, skip: nil) |
Get the entry if it exists or nil if it does not. If the key is a resource then it will always return an array. |
Db#del(key) |
Delete the key and all children of the key from the store. |
Db#count(key) |
The number of entries directly under a key if the key is a resource. If they key is an entry then 1 if the entry exists and 0 if it does not exist. |
Note(s):
- limit and skip are optional and only apply to resource keys, not entry keys.
db = Teton::Db.new
bozo_key = 'users/1'
inception_key = "#{bozo_key}/movies/1" # => users/1/movies/1
inception_actors_key = "#{inception_key}/actors" # => users/1/movies/1/actors
leo_key = "#{inception_actors_key}/1" # => users/1/movies/1/actors/1
tom_key = "#{inception_actors_key}/2" # => users/1/movies/1/actors/2
db.set(bozo_key, first: 'bozo', last: 'clown')
.set(inception_key, title: 'Inception', year: 2010)
.set(leo_key, first: 'Leonardo', last: 'DiCaprio', star: true)
.set(tom_key, first: 'Tom', last: 'Hardy', star: true)
Note(s):
#set
returns self.- If an inner key within the key does not exist then it will be added to the hierarchy.
bozo = db.get(bozo_key) # => Teton::Entry
inception = db.get(inception_key) # => Teton::Entry
leo = db.get(leo_key) # => Teton::Entry
tom = db.get(tom_key) # => Teton::Entry
inception_actors = db.get(inception_actors_key) # => [Teton::Entry]
Note(s):
- If a key does not exist then nil will be returned.
- If a key is for a resource then it will return an array.
db.del(leo_key)
.del(inception_key)
.del(bozo_key)
Note(s):
#del
returns self.- If an inner key is deleted then all child keys in the hierarchy are deleted.
The back-end: Teton::Stores::Memory
will be used by default. You can also pass in another back-end if one exists:
store = Teton::Stores::MySQL.new(host: '127.0.0.1', db: 'teton_entries')
db = Teton::Db.new(store: store)
Note(s):
- Each back-end may require specific configuration so it is up to you to check the desired back-end's documentation.
- Currently
Teton::Stores::MySQL
does not exist as an implementation but any store (i.e. MySQL, PostgeSQL, Redis, S3, traditional file systems) should all be possible.
Each back-end provides its own persistence mechanics. For example, Teton::Stores::Memory
provides persistence/serialization methods:
Method | Description |
---|---|
#load!(path( |
Load from a file on disk |
#save!(path) |
Save to a file on disk |
#from_json! |
Deserialize a passed in JSON string |
#to_json |
Return a serialized JSON string |
Basic steps to take to get this repository compiling:
- Install Ruby (check teton.gemspec for versions supported)
- Install bundler (gem install bundler)
- Clone the repository (git clone [email protected]:mattruggio/teton.git)
- Navigate to the root folder (cd teton)
- Install dependencies (bundle)
To execute the test suite run:
bin/rspec spec --format documentation
Alternatively, you can have Guard watch for changes:
bin/guard
Also, do not forget to run Rubocop:
bin/rubocop
And auditing the dependencies:
bin/bundler-audit check --update
Note: ensure you have proper authorization before trying to publish new versions.
After code changes have successfully gone through the Pull Request review process then the following steps should be followed for publishing new versions:
- Merge Pull Request into main
- Update
version.rb
using semantic versioning - Install dependencies:
bundle
- Update
CHANGELOG.md
with release notes - Commit & push main to remote and ensure CI builds main successfully
- Run
bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the.gem
file to rubygems.org.
Everyone interacting in this codebase, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.
This project is MIT Licensed.