Simple persist your model data to a .json file
Add this line to your application's Gemfile:
gem'json_model'And then execute:
$ bundle
Or install it yourself as:
$ gem install json_model
require'json_model'classBookincludeJsonModelfield:namefield:authorend# create some booksBook.new({name: 'Inferno',author: 'Dan Brown'}).saveBook.new({name: 'Das verlorene Symbol',author: 'Dan Brown'}).saveBook.new({name: 'Diabolus',author: 'Dan Brown'}).save# list all booksputs"\n--- List all books"Book.all.map{|book| puts"#{book.id} - #{book.name} by #{book.author}"}# find a book by idputs"\n--- Find book with id=1"book=Book.find(1)puts"Book: #{book.to_json}"# update a bookputs"\n--- Update name of book with id=1"book=Book.find(1)book.name='Illuminati'book.saveBook.all.map{|book| puts"#{book.id} - #{book.name} by #{book.author}"}# find a book by nameputs"\n--- Find book by name 'Illuminati'"book=Book.find_by(name: 'Illuminati')puts"Book: #{book.to_json}"# delete a bookputs"\n--- Delete book with Id=2"book=Book.find(2)book.destroyBook.all.map{|book| puts"#{book.id} - #{book.name} by #{book.author}"}$ ruby book.rb
- Fork it ( https://github.com/endorfin/json_model/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

