as_json_with_includes 0.1.2 → 0.1.3
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/README.md +39 -3
- data/lib/as_json_with_includes.rb +1 -0
- data/lib/as_json_with_includes/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: b89654eb74fabd0c5546624012e78c38a9239ffb
|
4
|
+
data.tar.gz: df3b18361523ac7eb66e29463b5b34e7f526f43c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be2de28e44c351a9d10cda236d6ec25e67b49102eea8537dd8c32278cbcf882c0e2ecd392ceab4334d4fef22abfd0b93abc214e76a21394c8cd61eae85e3b42c
|
7
|
+
data.tar.gz: c6fe595c262dc5aef9af8ee2bdfe5dcae85355c44223a42fdbb6ec75d28ec8bcdaa4d4707782720bcf8f2ff6794cfc150e0d77afb3c41fc6611ae81f80c7c512
|
data/README.md
CHANGED
@@ -1,8 +1,41 @@
|
|
1
1
|
# AsJsonWithIncludes
|
2
2
|
|
3
|
-
|
3
|
+
## Problem:
|
4
4
|
|
5
|
-
|
5
|
+
- We have complicated includes
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
includes = [:a, :b, :c, :d, {:e => {:f => [:g, :g]}}]
|
9
|
+
```
|
10
|
+
|
11
|
+
- We can use it like this:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
model = model_1.submodels.includes(includes)
|
15
|
+
```
|
16
|
+
|
17
|
+
- The data is now in rails and we have to convert the data to json but we cannot do `render :json => submodels, :include => includes`
|
18
|
+
this is because the ":include =>" attribute expects a different format:
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
[:a, :b, :c, :d, {:e => {:include => {:f => {:include => [:g, :h]}}}}]
|
22
|
+
```
|
23
|
+
|
24
|
+
which we have to manually write.
|
25
|
+
|
26
|
+
## Solution:
|
27
|
+
|
28
|
+
This gem takes active_record_includes of the form:
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
[:a, :b, :c, :d, {:e => {:f => [:g, :h]}}]
|
32
|
+
```
|
33
|
+
|
34
|
+
and returns:
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
[:a, :b, :c, :d, {:e => {:include => {:f => {:include => [:g, :h]}}}}]
|
38
|
+
```
|
6
39
|
|
7
40
|
## Installation
|
8
41
|
|
@@ -22,7 +55,10 @@ Or install it yourself as:
|
|
22
55
|
|
23
56
|
## Usage
|
24
57
|
|
25
|
-
|
58
|
+
```ruby
|
59
|
+
includes = [:a, :b, {c: :d}]
|
60
|
+
model = Model.where(...).as_json_with_includes(includes: includes)
|
61
|
+
```
|
26
62
|
|
27
63
|
## Development
|
28
64
|
|