restme 1.2.0 → 1.2.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: 0f3c9d79dc88d267a1198ec23b54f05d8af00367125b1cf1f3fcd6c458633b35
4
- data.tar.gz: 48c79f664b0fb61dea85fdd4d2d56d63520f7389c6b31adbead1c41a6b945268
3
+ metadata.gz: 9a2a5ee870751a00ca5907e773e8d1aaf34fefd68c66bdcbbd42a0809d38ca19
4
+ data.tar.gz: 8ef1ff2ab867c127615d53fa903808cc5579f961204cc9ff9306f217f1c7e4ae
5
5
  SHA512:
6
- metadata.gz: 80455f1ab99ddec14145d9ed3229c491abfd48c1d2db0fae6532d56ca3304783749d2cba38216ef6529ed6a2985743ed41c3feb2e3fb72273eb8c1a87eae332a
7
- data.tar.gz: e7033c0ded95c20fb3df221af86dff3801a67c80cd7b9f3ac4d070f4f64b979d385e01874bbceccdf0affac556752261ffc24e22acd485651d9163650083f8c8
6
+ metadata.gz: 062df3cf4301fad020426e57ee07eb373ab2751c03f6aed5928e32db4988f8283c4e20254c993515d617dbb4b1e581eae2492aad4aecb0fd2610b0cc38c3afbe
7
+ data.tar.gz: ade0cf78bcce6e49a3ecdeb2eb54513c7761c28bce0df20cdd1630bf61393962b68eb9394bdb6eb5e20c9ff04d619ad94932de1a3218ef1578321ca0ecce9fa0
data/README.md CHANGED
@@ -8,12 +8,15 @@ This gem manages your controller's responsibilities for:
8
8
  - Read Actions: Provide complete pagination, filtering, sorting, and field selection for records, all handled through query parameters (e.g., `http://127.0.0.1/products?name_equal=foo`).
9
9
  - Create/Update Actions: Enabling automatic creation and updating of records.
10
10
 
11
+ ## ℹ️ This doc reference latest version of Restme
12
+
13
+
11
14
  ## Installation
12
15
 
13
16
 
14
17
  GEMFILE:
15
18
  ```bash
16
- gem 'restme', '~> 1.1'
19
+ gem 'restme', '~> 1.2'
17
20
  ```
18
21
 
19
22
  INSTALL:
@@ -207,19 +210,10 @@ This rule defines which nested_fields are selectable (nested fields are model re
207
210
  module ProductsController::Field
208
211
  class Rules
209
212
  NESTED_SELECTABLE_FIELDS = {
210
- unit: {
211
- table_name: :units
212
- },
213
- establishment: {
214
- table_name: :establishments
215
- },
216
- category: {
217
- table_name: :categories
218
- },
219
- producer: { # When a nested field can be nil, Restme will not return the primary model unless a LEFT JOIN is explicitly used.
220
- table_name: :producers,
221
- join_type: :left_joins # Use that so Restme will generate a LEFT JOIN instead of an INNER JOIN. This will
222
- }
213
+ unit: {},
214
+ establishment: {},
215
+ category: {},
216
+ producer: {}
223
217
  }.freeze
224
218
  end
225
219
  end
@@ -364,6 +358,15 @@ Example:
364
358
 
365
359
  ```bash
366
360
  http://localhost:3000/api/v1/products?attachment_fields_select=image
361
+
362
+ {
363
+ "products": [
364
+ {
365
+ "id": 1,
366
+ "image_url": "http://localhost/image.png", // The field includes the `_url` suffix
367
+ }
368
+ ]
369
+ }
367
370
  ```
368
371
 
369
372
  <br><br>
@@ -39,7 +39,7 @@ module Restme
39
39
  @user_scope = user_scope
40
40
 
41
41
  return user_scope unless filterable_scope?
42
- return user_scope if record_not_found_errors
42
+ return none_scope if record_not_found_errors
43
43
 
44
44
  processed_scope
45
45
  end
@@ -22,11 +22,18 @@ module Restme
22
22
  include ::Restme::Shared::CurrentModel
23
23
  include ::Restme::Shared::RestmeCurrentUserRole
24
24
 
25
- attr_reader :filtered_scope, :sorted_scope, :paginated_scope, :fieldated_scope
25
+ attr_reader :sortable_scope_response, :paginable_scope_response
26
26
  attr_writer :restme_scope_errors, :restme_scope_status
27
27
 
28
+ SCOPE_ERROR_METHODS = %i[
29
+ per_page_errors
30
+ unknown_sortable_fields_errors
31
+ unallowed_filter_fields_errors
32
+ unallowed_select_fields_errors
33
+ ].freeze
34
+
28
35
  def pagination_response
29
- @pagination_response ||= restme_response
36
+ @pagination_response ||= restme_pagination_response
30
37
  end
31
38
 
32
39
  def model_scope_object
@@ -39,7 +46,7 @@ module Restme
39
46
 
40
47
  private
41
48
 
42
- def restme_response
49
+ def restme_pagination_response
43
50
  any_scope_errors
44
51
 
45
52
  restme_scope_errors.presence || {
@@ -49,10 +56,7 @@ module Restme
49
56
  end
50
57
 
51
58
  def any_scope_errors
52
- per_page_errors
53
- unknown_sortable_fields_errors
54
- unallowed_filter_fields_errors
55
- unallowed_select_fields_errors
59
+ SCOPE_ERROR_METHODS.each { |m| send(m) }
56
60
 
57
61
  restme_scope_errors
58
62
  end
@@ -64,8 +68,8 @@ module Restme
64
68
  def pagination
65
69
  {
66
70
  page: page_no,
67
- pages: pages(filtered_scope),
68
- total_items: total_items(filtered_scope)
71
+ pages: pages(filterable_scope_response),
72
+ total_items: total_items(filterable_scope_response)
69
73
  }
70
74
  end
71
75
 
@@ -80,10 +84,16 @@ module Restme
80
84
  end
81
85
 
82
86
  def custom_scope
83
- @filtered_scope = filterable_scope(user_scope)
84
- @sorted_scope = sortable_scope(filtered_scope)
85
- @paginated_scope = paginable_scope(sorted_scope)
86
- @fieldated_scope = fieldable_scope(paginated_scope)
87
+ return filterable_scope_response if filterable_scope_response.blank?
88
+
89
+ @sortable_scope_response = sortable_scope(filterable_scope_response)
90
+ @paginable_scope_response = paginable_scope(sortable_scope_response)
91
+
92
+ fieldable_scope(paginable_scope_response)
93
+ end
94
+
95
+ def filterable_scope_response
96
+ @filterable_scope_response ||= filterable_scope(user_scope)
87
97
  end
88
98
 
89
99
  def user_scope
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Restme
4
- VERSION = "1.2.0"
4
+ VERSION = "1.2.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restme
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - everson-ever