adequate_json 0.1.0 → 0.2.0
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 +10 -0
- data/lib/adequate_json/base.rb +2 -1
- data/lib/adequate_json/collection.rb +2 -2
- data/lib/adequate_json/serializer.rb +2 -2
- data/lib/adequate_json/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d4347cf905fe5ac337ae7136fb1d5d0c6d3725f12f4148d08933bfa57da56c8
|
4
|
+
data.tar.gz: e04e8f7b2d3e720268b9a46d4347d1a6e3c89a582ed94f70c9c16e2a105a1ce1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b29ffcb93cd855f54405dfd3958a912258f36d1d73c03b034fbc0c00cca34268e78152dfa1249f2b8b50d564a12bf2afc205373854e9d354e99b1fb1648e08e
|
7
|
+
data.tar.gz: 3508eb151aa0e4ac32289dd3f224bc6749b7f7dda8d96019febb3a2ff18bff433f51d59579bcd44f2c8ed36a611a98ba7f11eead7111a122b41cbe48b27b23d1
|
data/README.md
CHANGED
@@ -161,6 +161,16 @@ class ProductsController < ActionController::API
|
|
161
161
|
end
|
162
162
|
```
|
163
163
|
|
164
|
+
Builder variants default to :no_wrapper for all elements of the hash, but a specific variant can be specified for each element. To use a specific variant, provide it as a keyword argument:
|
165
|
+
|
166
|
+
```ruby
|
167
|
+
class ProductsController < ActionController::API
|
168
|
+
def show
|
169
|
+
render_json { product: Product.find(params[:id]), categories: Category.order(:name) }, variants: { product: :header }
|
170
|
+
end
|
171
|
+
end
|
172
|
+
```
|
173
|
+
|
164
174
|
### Pagination
|
165
175
|
|
166
176
|
As soon as you've added [Kaminari](https://github.com/kaminari/kaminari)
|
data/lib/adequate_json/base.rb
CHANGED
@@ -5,9 +5,10 @@ module AdequateJson
|
|
5
5
|
include Resolver
|
6
6
|
include Jsonizer
|
7
7
|
|
8
|
-
def initialize(model, json = nil, variant: nil)
|
8
|
+
def initialize(model, json = nil, variant: nil, variants: {})
|
9
9
|
@model = model
|
10
10
|
@variant = variant
|
11
|
+
@variants = variants
|
11
12
|
@json = json
|
12
13
|
end
|
13
14
|
|
@@ -3,7 +3,7 @@
|
|
3
3
|
require 'adequate_json/base'
|
4
4
|
module AdequateJson
|
5
5
|
class Collection < AdequateJson::Base
|
6
|
-
def initialize(collection, json = nil, variant: nil)
|
6
|
+
def initialize(collection, json = nil, variant: nil, variants: {})
|
7
7
|
@first_level = true if json.nil?
|
8
8
|
super
|
9
9
|
@variant ||= :no_wrapper
|
@@ -13,7 +13,7 @@ module AdequateJson
|
|
13
13
|
with_jbuilder do |json|
|
14
14
|
json.set!(collection_key) do
|
15
15
|
json.array! @model do |item|
|
16
|
-
serialize item, variant: @variant
|
16
|
+
serialize item, variant: @variant, variants: @variants
|
17
17
|
end
|
18
18
|
end
|
19
19
|
attach_pagination(json)
|
@@ -4,8 +4,8 @@ module AdequateJson
|
|
4
4
|
module Serializer
|
5
5
|
include AdequateJson::Resolver
|
6
6
|
|
7
|
-
def render_json(model, variant: nil, **options)
|
8
|
-
render json: choose_serializer(model, variant: variant), **options
|
7
|
+
def render_json(model, variant: nil, variants: {}, **options)
|
8
|
+
render json: choose_serializer(model, variant: variant, variants: variants), **options
|
9
9
|
end
|
10
10
|
|
11
11
|
def render_error(error, model = nil, includes: nil, **options)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: adequate_json
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jef Mathiot
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2025-01-03 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: jbuilder
|
@@ -150,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
150
150
|
- !ruby/object:Gem::Version
|
151
151
|
version: '0'
|
152
152
|
requirements: []
|
153
|
-
rubygems_version: 3.5.
|
153
|
+
rubygems_version: 3.5.9
|
154
154
|
signing_key:
|
155
155
|
specification_version: 4
|
156
156
|
summary: Yet another JSON serialization library
|