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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +41 -7
- data/lib/json_model/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4fb405d2bbac6a3bab9456c0e6340ce04bdad9ff
|
4
|
+
data.tar.gz: 03b10010641553a05587929b17c837ac31103d8f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e9af4397cf05bc5389e6e023a4e2d6cd72978bcc06cbfd48aa08faee4ea48062410cbb3a9370868b7b61d3db76d5a19a3969fbee6cd19153b91de97297275cd
|
7
|
+
data.tar.gz: 19e1f2e12f198832cd42fa67efbd9e7ea6c9dc79237b9baf451188d0ff58eb4699f937a61b657fd9a1e3affb89603545dfbbb5cef18bef12d4a6f83d9607b523
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# JsonModel
|
2
2
|
|
3
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
|
data/lib/json_model/version.rb
CHANGED