Yamlet
Yamlet is a tiny library (< 100 lines of code) which injects CRUD functionalities to your Plain Old Ruby Objects and store data on a YAML file using YAML::Store.
Perfect for creating small applications (for demo/prototyping purposes) where you only need a single YAML file to store everything and removes the constraint of setting up a database.
Installation
Add this line to your application's Gemfile:
gem 'yamlet'
And then execute:
$ bundle
Or install it yourself as:
$ gem install yamlet
Usage
Configuration
First, create a YAML file somewhere then tell Yamlet where to find that file which we'll be using for storing data.
Yamlet.repository_file = "/path/to/repository.yml"
NOTE: A RepositoryNotFound
error will be raised when Yamlet can't locate the YAML file.
Using Yamlet with Classes
class User
include Yamlet.model
#...
end
After including Yamlet.model
in your class, notice that the YAML file will
automatically be updated.
# /path/to/repository.yml
---
user: []
Methods
.all
User.all #=> []
User.create(name: "Grumpy Kid")
User.all #=> [{"id"=>1, "name"=>"Grumpy Kid"}]
.find
User.find(1) #=> {"id"=>1, "name"=>"Grumpy Kid"}
.create
User.create(name: "Grumpy Kid")
#=> {"id"=>1, "name"=>"Grumpy Kid"}
.update
User.update(1, name: "Grumpy Dad")
#=> {"id"=>1, "name"=>"Grumpy Dad"}
.destroy
User.destroy(1)
User.all #=> []
.destroy_all
5.times { |i| User.create(name: "Grumpy #{i}") }
User.destroy_all #=> []
Run the tests
$ rspec spec
Contributing
- Fork it ( https://github.com/[my-github-username]/yamlet/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