README.md in json_model-0.1.0 vs README.md in json_model-0.1.1

- old
+ new

@@ -1,11 +1,9 @@ # JsonModel -Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/json_model`. To experiment with that code, run `bin/console` for an interactive prompt. +Simple persist your model data to a .json file -TODO: Delete this and the text above, and describe your gem - ## Installation Add this line to your application's Gemfile: ```ruby @@ -20,16 +18,52 @@ $ gem install json_model ## Usage -TODO: Write usage instructions here +book.rb -## Development + require 'json_model' -After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment. + class Book + include JsonModel -To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). + field :name + field :author + end + + # create some books + Book.new({name: 'Inferno', author: 'Dan Brown'}).save + Book.new({name: 'Das verlorene Symbol', author: 'Dan Brown'}).save + Book.new({name: 'Diabolus', author: 'Dan Brown'}).save + + # list all books + puts "\n--- List all books" + Book.all.map{|book| puts "#{book.id} - #{book.name} by #{book.author}" } + + # find a book by id + puts "\n--- Find book with id=1" + book = Book.find(1) + puts "Book: #{book.to_json}" + + # update a book + puts "\n--- Update name of book with id=1" + book = Book.find(1) + book.name = 'Illuminati' + book.save + Book.all.map{|book| puts "#{book.id} - #{book.name} by #{book.author}" } + + # find a book by name + puts "\n--- Find book by name 'Illuminati'" + book = Book.find_by(name: 'Illuminati') + puts "Book: #{book.to_json}" + + # delete a book + puts "\n--- Delete book with Id=2" + book = Book.find(2) + book.destroy + Book.all.map{|book| puts "#{book.id} - #{book.name} by #{book.author}" } + ## Contributing 1. Fork it ( https://github.com/[my-github-username]/json_model/fork ) 2. Create your feature branch (`git checkout -b my-new-feature`)