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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3cbacee74d3afeea518276751f6ce7832d7da1dc
4
- data.tar.gz: d9a1dcfbfb805a69d85d0a4d21830f19cfe9ce3e
3
+ metadata.gz: b89654eb74fabd0c5546624012e78c38a9239ffb
4
+ data.tar.gz: df3b18361523ac7eb66e29463b5b34e7f526f43c
5
5
  SHA512:
6
- metadata.gz: 295ff06f4d773660e200becbe885ab7298c04ecd66c40ed4dfef4ca5f32919818986438bf2ca7e0397219b67965a4d46800c65630d41887642fd2cebec0cb024
7
- data.tar.gz: 89a38260fceeb60404190394e43041a94666611882570ea08d357f7d6e4705293dd9fd7ad237027e148313c5065deeb155132292a0d00c6ba7471dbe6c890a91
6
+ metadata.gz: be2de28e44c351a9d10cda236d6ec25e67b49102eea8537dd8c32278cbcf882c0e2ecd392ceab4334d4fef22abfd0b93abc214e76a21394c8cd61eae85e3b42c
7
+ data.tar.gz: c6fe595c262dc5aef9af8ee2bdfe5dcae85355c44223a42fdbb6ec75d28ec8bcdaa4d4707782720bcf8f2ff6794cfc150e0d77afb3c41fc6611ae81f80c7c512
data/README.md CHANGED
@@ -1,8 +1,41 @@
1
1
  # AsJsonWithIncludes
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/as_json_with_includes`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ ## Problem:
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
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
- TODO: Write usage instructions here
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
 
@@ -1,4 +1,5 @@
1
1
  require "as_json_with_includes/version"
2
+ require 'active_record'
2
3
 
3
4
  module AsJsonWithIncludes
4
5
  module BasePatch
@@ -1,3 +1,3 @@
1
1
  module AsJsonWithIncludes
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: as_json_with_includes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Truong Hoang Dung