json-pie 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +52 -23
  3. data/lib/json/pie/version.rb +1 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a63d4d0b3a9e543fbb77724003a4e00b54b4019fc4aa96effde7517ea40967bf
4
- data.tar.gz: a355d4b17fe3ae44c243073d86da4766825d2db1b52d876d7e8fe034be90ecfe
3
+ metadata.gz: 8bc688a815ec0c446b67a8f9a05bb742ff0ae19e9f3207b9241630b9d13acbd9
4
+ data.tar.gz: ee0357b235fabfdc886ad9821cd8d4d096a59d0016b4acbc6cfc32c88ca8bf96
5
5
  SHA512:
6
- metadata.gz: 0a295acde72a3e8d5b6b5fb2161e3112041948e3979a740782b7b50df0b8a601f189e3f0fbebf11601a6f2096078acccbbf370298a24618952f4b47fe6f8cd44
7
- data.tar.gz: a6fb5a2ee5cb6c2ca9473fc3b2295c313302d58154a7378091168445df000bdf6d7344f3ecb84c75df205e1f9907aba493145ec274eff1966979beb018e88eba
6
+ metadata.gz: c9f9617599a2ff972f648d986436bbc645a605fc5e2ac396ffadb4527cb189ac5a0af0dae1c10cafbcab69424c2f951e0e9a204b9823bdd90eaea68dee56e840
7
+ data.tar.gz: 471dd338d3caa975998bad5d77f03ee4c474801126825f13fb72a876d40e974583b9bba0dd9695c6d5cb96cd1533a3756aaa082e39bb8de287854d27ef6c288d
data/README.md CHANGED
@@ -1,39 +1,68 @@
1
- # Json::Pie
1
+ # JSON::Pie
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/pie`. 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
+ Parse JSON:API data structures into Rails ActiveRecord structures.
6
4
 
7
5
  ## Installation
8
6
 
9
- Add this line to your application's Gemfile:
10
-
11
- ```ruby
12
- gem 'json-pie'
7
+ ```
8
+ gem "json-pie"
13
9
  ```
14
10
 
15
- And then execute:
16
-
17
- $ bundle install
18
-
19
- Or install it yourself as:
11
+ ## Usage
20
12
 
21
- $ gem install json-pie
13
+ Your models:
22
14
 
23
- ## Usage
15
+ ```ruby
16
+ class User < ActiveRecord::Base
17
+ has_many :articles
18
+ end
24
19
 
25
- TODO: Write usage instructions here
20
+ class Article < ActiveRecord::Base
21
+ belongs_to :user
22
+ end
23
+ ```
26
24
 
27
- ## Development
25
+ In your controller:
28
26
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
27
+ ```ruby
28
+ class ArticleController
29
+ def create
30
+ article = JSON::Pie.parse params
31
+ article.save!
32
+ render json: article, status: :created
33
+ end
34
+ end
35
+ ```
30
36
 
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`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
37
+ Then send this JSON structure to your application will create a new article with `#<User @id=1 ...>` as the author.
38
+
39
+ ```json
40
+ {
41
+ "data": {
42
+ "type": "article",
43
+ "attributes": {
44
+ "title": "New article"
45
+ },
46
+ "relationships": {
47
+ "user": {
48
+ "data": {
49
+ "type": "user",
50
+ "id": 1
51
+ }
52
+ }
53
+ }
54
+ }
55
+ }
56
+ ```
32
57
 
33
- ## Contributing
58
+ ### Decoupling from your models
34
59
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/json-pie.
60
+ It's fairly easy to decouple the publis JSON:API that you parse from the actual data structure beneath by using the options.
36
61
 
37
- ## License
62
+ ```ruby
63
+ JSON::Pie.parse(params, **options)
64
+ ```
38
65
 
39
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
66
+ | option | description |
67
+ | ------ | ----------- |
68
+ | `type_map` | A hash that maps JSON:API types to the actual models in your system. E.g. `{ author: :user }` |
@@ -2,6 +2,6 @@
2
2
 
3
3
  module JSON
4
4
  module Pie
5
- VERSION = "0.0.1"
5
+ VERSION = "0.0.2"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json-pie
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emil Kampp