Skip to content
/ yamlet Public

Inject CRUD functionalities to your Plain Old Ruby Objects and store data in a YAML file

Notifications You must be signed in to change notification settings

rbmrclo/yamlet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

  1. Fork it ( https://github.com/[my-github-username]/yamlet/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

About

Inject CRUD functionalities to your Plain Old Ruby Objects and store data in a YAML file

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages