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 +4 -4
- data/README.md +17 -14
- data/lib/restme/scope/filter/rules.rb +1 -1
- data/lib/restme/scope/rules.rb +23 -13
- data/lib/restme/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a2a5ee870751a00ca5907e773e8d1aaf34fefd68c66bdcbbd42a0809d38ca19
|
4
|
+
data.tar.gz: 8ef1ff2ab867c127615d53fa903808cc5579f961204cc9ff9306f217f1c7e4ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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
|
-
|
212
|
-
},
|
213
|
-
|
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>
|
data/lib/restme/scope/rules.rb
CHANGED
@@ -22,11 +22,18 @@ module Restme
|
|
22
22
|
include ::Restme::Shared::CurrentModel
|
23
23
|
include ::Restme::Shared::RestmeCurrentUserRole
|
24
24
|
|
25
|
-
attr_reader :
|
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 ||=
|
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
|
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
|
-
|
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(
|
68
|
-
total_items: total_items(
|
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
|
-
|
84
|
-
|
85
|
-
@
|
86
|
-
@
|
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
|
data/lib/restme/version.rb
CHANGED