infinum_json_api_setup 0.1.0 → 0.1.1

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: fd0a0f31918bb2f7f2c2fd1c89c7ef8704292bba7590c980c54ac8daa809c321
4
- data.tar.gz: afb709b1deeb7891a4f7a65a248ffaebcbd4f0ad874e48d1c7c21dae623d3cb1
3
+ metadata.gz: 02c01a6edfee1465e478a630629fd38b0cd35f08a84a32a2eac73c353440bebc
4
+ data.tar.gz: f94a539f053417cfc9e0a4c938eaa594a02e422930fee2f46b80aebffeaa17e0
5
5
  SHA512:
6
- metadata.gz: d4c5c8b5f7564d095d43efa4a292263dc8c5cc65c4066f5ee3078b7b7afefcbb4879570ec6474ae6aa690a775afbd97f319ce6d6d3c55585314bbf455a0a5ce8
7
- data.tar.gz: 60da19ebe9c6ebc6edf1fba046621cd966ecb5c4a0436fcc251ac5a18a946e6323a7f5359fc11632a434abfc886cf61eea7c256b364eccb2319a29eac0bfd0c8
6
+ metadata.gz: eadacbfe9298f7345e3f8a639b5dee0d39515b030a9519fa9c020667d2dfe65f52a7326971853dbb52a5a25b5aea407e049da466ea6e7bcf86fe49765568fc0d
7
+ data.tar.gz: 6d811bc78b9f2e999a40c5e08d250277cf5f70bc0307b6f61fba1f336907a36b6f813dd57fb6bcdeebb5d26fc789711521bbae0c17f103bee5ac27449a5973b0
data/CHANGELOG.md CHANGED
@@ -8,6 +8,11 @@ This projects adheres to [Semantic Versioning](https://semver.org/) and [Keep a
8
8
 
9
9
  ### Changes
10
10
 
11
+ ## [0.1.1] - 2026-08-13
12
+
13
+ ### Fixed
14
+ - Merge controller-provided `meta` into pagination meta instead of replacing it when rendering paginated JSON:API collections
15
+
11
16
  ## [0.1.0] - 2025-11-03
12
17
 
13
18
  ### Added
data/README.md CHANGED
@@ -66,6 +66,17 @@ def destroy
66
66
  end
67
67
  ```
68
68
 
69
+ For paginated collections, pass `pagination_details` from your query object. You can add extra collection-level fields to `meta`; they are merged with pagination meta instead of replacing it.
70
+ ```ruby
71
+ def index
72
+ q = Users::Query.new(User.all, params.to_unsafe_hash)
73
+
74
+ respond_with q.results,
75
+ pagination_details: q.pagination_details,
76
+ meta: { total_unread: current_user.unread_notifications_count }
77
+ end
78
+ ```
79
+
69
80
  ## Internals
70
81
  This section explains the under-the-hood behavior of the library.
71
82
 
@@ -4,9 +4,11 @@ module InfinumJsonApiSetup
4
4
  # @param [Hash] opts
5
5
  # @option opts [Hash] :params
6
6
  # @option opts [Object] :pagination_details
7
- def initialize(params:, pagination_details:)
7
+ # @option opts [Hash] :extra_meta additional collection meta merged into pagination meta
8
+ def initialize(params:, pagination_details:, extra_meta: nil)
8
9
  @params = params
9
10
  @pagination_details = pagination_details
11
+ @extra_meta = extra_meta || {}
10
12
  end
11
13
 
12
14
  # @return [Hash]
@@ -23,8 +25,13 @@ module InfinumJsonApiSetup
23
25
 
24
26
  attr_reader :params
25
27
  attr_reader :pagination_details
28
+ attr_reader :extra_meta
26
29
 
27
30
  def meta
31
+ pagination_meta.merge(extra_meta)
32
+ end
33
+
34
+ def pagination_meta
28
35
  return {} unless pagination_details
29
36
 
30
37
  {
@@ -19,10 +19,12 @@ ActiveSupport.on_load(:action_controller) do
19
19
  "#{controller_path.classify.pluralize}::Serializer".constantize
20
20
  end
21
21
  options = InfinumJsonApiSetup::JsonApi::SerializerOptions.new(
22
- params: params.to_unsafe_h, pagination_details: opts[:pagination_details]
22
+ params: params.to_unsafe_h,
23
+ pagination_details: opts[:pagination_details],
24
+ extra_meta: opts[:meta]
23
25
  ).build
24
26
 
25
- serializer.new(resources, options.merge(opts)).serializable_hash.to_json
27
+ serializer.new(resources, options.merge(opts.except(:meta))).serializable_hash.to_json
26
28
  end
27
29
  end
28
30
  end
@@ -1,3 +1,3 @@
1
1
  module InfinumJsonApiSetup
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.1.1'.freeze
3
3
  end
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- infinum_json_api_setup (0.1.0)
4
+ infinum_json_api_setup (0.1.1)
5
5
  accept_language (~> 2.0)
6
6
  json_schemer (>= 0.2, < 3)
7
7
  jsonapi-query_builder
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- infinum_json_api_setup (0.1.0)
4
+ infinum_json_api_setup (0.1.1)
5
5
  accept_language (~> 2.0)
6
6
  json_schemer (>= 0.2, < 3)
7
7
  jsonapi-query_builder
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe InfinumJsonApiSetup::JsonApi::SerializerOptions do
4
+ subject(:built_options) do
5
+ described_class.new(
6
+ params: params,
7
+ pagination_details: pagination_details,
8
+ extra_meta: extra_meta
9
+ ).build
10
+ end
11
+
12
+ let(:params) { {} }
13
+ let(:extra_meta) { nil }
14
+ let(:pagination_details) do
15
+ instance_double(
16
+ Pagy,
17
+ page: 1,
18
+ pages: 2,
19
+ count: 10,
20
+ last: 2,
21
+ prev: nil,
22
+ next: 2,
23
+ vars: { outset: 0, items: 20 }
24
+ )
25
+ end
26
+
27
+ before do
28
+ allow(Rails.application.routes.url_helpers).to receive(:url_for).and_return('http://example.com')
29
+ end
30
+
31
+ it 'includes pagination meta' do
32
+ expect(built_options[:meta]).to include(
33
+ current_page: 1,
34
+ total_pages: 2,
35
+ total_count: 10,
36
+ padding: 0,
37
+ page_size: 20,
38
+ max_page_size: Pagy::DEFAULT[:max_items]
39
+ )
40
+ end
41
+
42
+ context 'when extra meta is present' do
43
+ let(:extra_meta) { { total_unread: 5 } }
44
+
45
+ it 'merges extra meta into pagination meta' do
46
+ expect(built_options[:meta]).to include(
47
+ current_page: 1,
48
+ total_unread: 5
49
+ )
50
+ end
51
+ end
52
+
53
+ context 'when extra meta is an empty hash' do
54
+ let(:extra_meta) { {} }
55
+
56
+ it 'keeps pagination meta' do
57
+ expect(built_options[:meta]).to include(current_page: 1, total_pages: 2)
58
+ end
59
+ end
60
+
61
+ context 'when pagination details are absent' do
62
+ let(:pagination_details) { nil }
63
+ let(:extra_meta) { { custom_count: 3 } }
64
+
65
+ it 'returns only extra meta' do
66
+ expect(built_options[:meta]).to eq(custom_count: 3)
67
+ end
68
+ end
69
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: infinum_json_api_setup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Team Backend @ Infinum
@@ -252,6 +252,7 @@ files:
252
252
  - spec/dummy/storage/.keep
253
253
  - spec/factories/location.rb
254
254
  - spec/factories/location_label.rb
255
+ - spec/infinum_json_api_setup/json_api/serializer_options_spec.rb
255
256
  - spec/infinum_json_api_setup/rspec/helpers/response_helper_spec.rb
256
257
  - spec/infinum_json_api_setup/rspec/matchers/have_empty_data_spec.rb
257
258
  - spec/infinum_json_api_setup/rspec/matchers/have_error_pointer_spec.rb