render_json_rails 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +76 -19
- data/lib/render_json_rails/version.rb +1 -1
- data/render_json_rails.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 90cc1574d9f07dd9306bb4416625ad680c8a2777bd62de9529b7a110576d6928
|
4
|
+
data.tar.gz: be85fbe2ca6984d1efe32ad8531b6913d755761259c9cbb143b007663fb59340
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b533b034543b5bbce37a7d8d1a039fb94d8c64557c8635a998c7459499868c70cfdd2d593110ca2389d9724dd7f436cfc14d506287e01967e7a9ab0fa3f2347d
|
7
|
+
data.tar.gz: b9ca7bd1f3221de4739824db73dfb5a868bd5725d3528103eee5ff368825d7477eb7700398aef46804d64efccdc749d75da2806d4d01b1150d42c0f255a6fbd6
|
data/README.md
CHANGED
@@ -1,45 +1,102 @@
|
|
1
1
|
# RenderJsonRails
|
2
2
|
|
3
|
-
|
3
|
+
RenderJsonRails pozwala w łatwy sposób dodać możliwość renderowania JSON z ActiveRecord-ów z zależnościami (has_many itp).
|
4
|
+
Dzięki temu łatwo jest stworzyć backend Json API np. do pracy z Reactem lub Vue.js
|
4
5
|
|
5
|
-
|
6
|
+
## Przykład
|
6
7
|
|
7
|
-
|
8
|
+
```ruby
|
8
9
|
|
9
|
-
|
10
|
+
class Team < ActiveRecord::Base
|
11
|
+
has_many :users
|
12
|
+
|
13
|
+
include RenderJsonRails::Concern
|
14
|
+
|
15
|
+
render_json_config name: :team,
|
16
|
+
includes: {
|
17
|
+
users: User
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
class User < ActiveRecord::Base
|
22
|
+
belongs_to :team
|
23
|
+
|
24
|
+
include RenderJsonRails::Concern
|
25
|
+
|
26
|
+
render_json_config name: :user,
|
27
|
+
includes: {
|
28
|
+
team: Team
|
29
|
+
}
|
30
|
+
end
|
31
|
+
```
|
32
|
+
|
33
|
+
Dodajemy też w kontrolerze ```teams_controller.rb```
|
10
34
|
|
11
35
|
```ruby
|
12
|
-
|
36
|
+
include RenderJsonRails::Helper
|
37
|
+
|
38
|
+
def index
|
39
|
+
@team = Team.all
|
40
|
+
respond_to do |format|
|
41
|
+
format.html
|
42
|
+
format.json { render_json @team }
|
43
|
+
end
|
44
|
+
end
|
45
|
+
```
|
46
|
+
|
47
|
+
i możemy już otrzymać JSON team-u wraz z userami
|
48
|
+
|
49
|
+
```html
|
50
|
+
http://example.test/teams/1.json?include=users
|
51
|
+
```
|
13
52
|
|
14
|
-
|
53
|
+
możemy też określić jakie pola mają być w json
|
15
54
|
|
16
|
-
|
17
|
-
|
18
|
-
end
|
55
|
+
```html
|
56
|
+
http://example.test/teams/1.json?fields[team]=name,description
|
19
57
|
```
|
20
58
|
|
21
|
-
|
59
|
+
i możemy łączyć to z include
|
22
60
|
|
23
|
-
|
61
|
+
```html
|
62
|
+
http://example.text/teams/1.json?fields[team]=name,description&fields[user]=email,name&include=users
|
63
|
+
```
|
24
64
|
|
25
|
-
|
65
|
+
## Pełny opis ```render_json_config```
|
26
66
|
|
27
|
-
|
67
|
+
```ruby
|
68
|
+
render_json_config name: :team,
|
69
|
+
except: [:account_id, :config], # tych pól nie będzie w json-ie
|
70
|
+
methods: [:image], # te metody zostaną dołączone
|
71
|
+
allowed_methods: [:members], # te metody mogą być dodane przez parametr fileds np: fields[team]=id,members
|
72
|
+
includes: { # to mozna dołączać za pomoca parametru include np include=users,category
|
73
|
+
users: Users,
|
74
|
+
cateogry: Category
|
75
|
+
}
|
76
|
+
```
|
28
77
|
|
29
|
-
##
|
78
|
+
## Installation
|
30
79
|
|
31
|
-
|
80
|
+
Add this line to your application's Gemfile:
|
32
81
|
|
33
|
-
|
82
|
+
```ruby
|
83
|
+
gem 'render_json_rails', git: 'https://github.com/intum/render_json_rails'
|
84
|
+
```
|
34
85
|
|
35
|
-
|
86
|
+
And then execute:
|
87
|
+
|
88
|
+
$ bundle install
|
36
89
|
|
37
|
-
|
90
|
+
Or install it yourself as:
|
91
|
+
|
92
|
+
$ gem install render_json_rails
|
38
93
|
|
39
94
|
## Contributing
|
40
95
|
|
41
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
96
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/intum/render_json_rails.
|
97
|
+
|
42
98
|
|
99
|
+
## TMP
|
43
100
|
|
44
101
|
Tworzenie gema
|
45
102
|
|
data/render_json_rails.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
9
9
|
|
10
10
|
spec.summary = "Simle JSON API render like JonApi"
|
11
11
|
spec.description = "render json with 'includes' and 'fields' with simple config"
|
12
|
-
spec.homepage = "https://
|
12
|
+
spec.homepage = "https://github.com/intum/render_json_rails"
|
13
13
|
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
14
14
|
|
15
15
|
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: render_json_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcin
|
@@ -29,7 +29,7 @@ files:
|
|
29
29
|
- lib/render_json_rails/helper.rb
|
30
30
|
- lib/render_json_rails/version.rb
|
31
31
|
- render_json_rails.gemspec
|
32
|
-
homepage: https://
|
32
|
+
homepage: https://github.com/intum/render_json_rails
|
33
33
|
licenses:
|
34
34
|
- MIT
|
35
35
|
metadata: {}
|