json_model 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ee86600ff328e9d32d69b0100a2923f982738cd6
4
- data.tar.gz: 71d6adbbe658e4c10b75f933fc1531dbfe251ec3
3
+ metadata.gz: 4fb405d2bbac6a3bab9456c0e6340ce04bdad9ff
4
+ data.tar.gz: 03b10010641553a05587929b17c837ac31103d8f
5
5
  SHA512:
6
- metadata.gz: 106ecccd9d424e3d1109910434acb4686cc91b0e2d31ad93d754c2ceac4d21f84847012479caadd619ec9ba4ac29c79cf13287dba535d9026acd2ba26b22014e
7
- data.tar.gz: 3a64ccbf052ea85fe24a1b544817ae833a71b35d198536910f99e26b0821d329423c1820292bf5a94ba395c117e5544b2bda0d5aa19ce19e47f778064c684c96
6
+ metadata.gz: 7e9af4397cf05bc5389e6e023a4e2d6cd72978bcc06cbfd48aa08faee4ea48062410cbb3a9370868b7b61d3db76d5a19a3969fbee6cd19153b91de97297275cd
7
+ data.tar.gz: 19e1f2e12f198832cd42fa67efbd9e7ea6c9dc79237b9baf451188d0ff58eb4699f937a61b657fd9a1e3affb89603545dfbbb5cef18bef12d4a6f83d9607b523
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- json_model (0.1.0)
4
+ json_model (0.1.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # JsonModel
2
2
 
3
- 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.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ Simple persist your model data to a .json file
6
4
 
7
5
  ## Installation
8
6
 
@@ -22,13 +20,49 @@ Or install it yourself as:
22
20
 
23
21
  ## Usage
24
22
 
25
- TODO: Write usage instructions here
23
+ book.rb
24
+
25
+ require 'json_model'
26
+
27
+ class Book
28
+ include JsonModel
29
+
30
+ field :name
31
+ field :author
32
+ end
33
+
34
+ # create some books
35
+ Book.new({name: 'Inferno', author: 'Dan Brown'}).save
36
+ Book.new({name: 'Das verlorene Symbol', author: 'Dan Brown'}).save
37
+ Book.new({name: 'Diabolus', author: 'Dan Brown'}).save
38
+
39
+ # list all books
40
+ puts "\n--- List all books"
41
+ Book.all.map{|book| puts "#{book.id} - #{book.name} by #{book.author}" }
42
+
43
+ # find a book by id
44
+ puts "\n--- Find book with id=1"
45
+ book = Book.find(1)
46
+ puts "Book: #{book.to_json}"
47
+
48
+ # update a book
49
+ puts "\n--- Update name of book with id=1"
50
+ book = Book.find(1)
51
+ book.name = 'Illuminati'
52
+ book.save
53
+ Book.all.map{|book| puts "#{book.id} - #{book.name} by #{book.author}" }
26
54
 
27
- ## Development
55
+ # find a book by name
56
+ puts "\n--- Find book by name 'Illuminati'"
57
+ book = Book.find_by(name: 'Illuminati')
58
+ puts "Book: #{book.to_json}"
28
59
 
29
- 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.
60
+ # delete a book
61
+ puts "\n--- Delete book with Id=2"
62
+ book = Book.find(2)
63
+ book.destroy
64
+ Book.all.map{|book| puts "#{book.id} - #{book.name} by #{book.author}" }
30
65
 
31
- 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).
32
66
 
33
67
  ## Contributing
34
68
 
@@ -1,3 +1,3 @@
1
1
  module JsonModel
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - René Kersten