A simple, flat-file datastore for Ruby.
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.



A simple, flat-file datastore for Ruby.

Getting Started

Cabi is a flat-file datastore where data is stored by directory stucture and accessed by colon-delimited strings. Here's how to get started:

$ gem install cabi
$ cabi init --mock    # use --mock to init cabi data with some fake data

Then access your data like so:

$ irb
  > require 'cabi'
  > Cabi.read('pages:about:body')
    => "<h1>Hello, Cabi!</h1>"


Assuming your cabi-data folder has the following structure:

├── info.yml
├── nav.yml
├── pages
│   └── about
│       ├── body.html
│       ├── meta.yml
│       ├── person-1.html
│       ├── person-2.html
│       └── person-3.html
└── posts
    └── random-article
        ├── index.html
        └── nav.html

You could then query your data like so:

# Simple selection
Cabi.read('pages:about:body')                 # contents of page/about/body.html

# Selection with/without explicit file extension
Cabi.read('posts:some-article:index')         # contents of posts/some-article/index.html
Cabi.read('posts:some-article:index.html')    # contents of posts/some-article/index.html

# Bulk selection - since Cabi uses dir globbing 
# under the hood, any valid dir glob in your 
# selection will work.
Cabi.read('pages:about:*')                    # an array of body.html and meta.yml contents
Cabi.read('pages:about:person-*')             # an array of all person-* html files
Cabi.read('**/*')                             # an array of all files in data
Cabi.read('**/*').length                      # 9

# Selection within YAML files
Cabi.read('pages:about:meta:foo:bar')         # contents of ['foo']['bar'] in page/about/meta.yml hash
Cabi.read('pages:about:meta.yml:foo:bar')     # same as above
Cabi.read('info:foo:bar:baz')                 # contents of ['foo']['bar']['baz'] in info.yml hash
Cabi.read('info.yml:foo:bar:baz')             # same as above

# Return a file path for a Cabi ID.
Cabi.file('pages:about:meta:foo:bar')         # path fo file at /pages/about/meta/foo/bar
Cabi.path_to_id('/pages/about/meta/foo/bar')  # pages:about:meta:foo:bar

Custom Data Directory

Cabi assumes that your data directory is either a folder at the top level of your project with a .cabi-data file in it (to indicate that it's the data directory). If one is not found, the data directory defaults to ./cabi-data.

For instance, if you had a folder called super-data located inside of your project's root that had a file called .cabi-data inside of it, this folder would be treated as your data directory.


Cabi Icon designed by Michela Tannoia, from The Noun Project.


Run the test suite by running rake test in the parent directory.

Building Gem Manually

$ gem build cabi.gemspec
$ gem install ./cabi-<VERSION>.gem


Find me online @brianmgonzalez