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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5b468fd9f03d2c352e7773d349b63961b989d8c6a6f019b97c140f950568bc3f
4
- data.tar.gz: 15f7842cd39c754e8a4df4f5509e04152de63aa20a2cf2b34dbd6d773cc54099
3
+ metadata.gz: 8d4347cf905fe5ac337ae7136fb1d5d0c6d3725f12f4148d08933bfa57da56c8
4
+ data.tar.gz: e04e8f7b2d3e720268b9a46d4347d1a6e3c89a582ed94f70c9c16e2a105a1ce1
5
5
  SHA512:
6
- metadata.gz: 153f935993fbc16160897afec263173ef90ec68b6e8ae66c32c2f83db74aa4fb6489d917e04ffd294427b8eb7b92c63c9de3dff2dcc00ceadc0bf30dfbcff804
7
- data.tar.gz: b789c736fe4610b0e27e0b9bf4dd60e9d333cb456805363e9f45ffe9d1a86247530da0c9f2febcfb61e058f4359f291ffebee2624d3c5f58aa359a509846f272
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)
@@ -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)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AdequateJson
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
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.1.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: 2024-11-20 00:00:00.000000000 Z
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.23
153
+ rubygems_version: 3.5.9
154
154
  signing_key:
155
155
  specification_version: 4
156
156
  summary: Yet another JSON serialization library