restme 1.2.0 → 1.2.2
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/field/rules.rb +4 -0
- data/lib/restme/scope/filter/rules.rb +1 -1
- data/lib/restme/scope/rules.rb +29 -17
- 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: 1719cb8e1a96b0e12a5015c3eca4c6acfdb3542d6df849f84abdd2aea05a812b
|
4
|
+
data.tar.gz: d49bac58ef0983dbbfd4f56710c2b31f8cfe01e1e0d62f886c296b0ea88d98ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e703777e66829853afd8fcb560b2d02e3760249ef604d6af9deb9ee6419dcbd5f34f09589d787a9010fd52ac6b78fc744628e77306635bc5b24f9d0a5ec9ec56
|
7
|
+
data.tar.gz: 474185500814429aed08447b12b89cf9a5109b133354b8ba347d01cb1de7cc81d4a23047e4159761ea6ddb120719e6b4ae3c792222c752c9270f589dd39c7313
|
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.1'
|
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>
|
@@ -19,6 +19,10 @@ module Restme
|
|
19
19
|
scoped = select_nested_scope(scoped) if valid_nested_fields_select
|
20
20
|
|
21
21
|
insert_attachments(scoped)
|
22
|
+
rescue ActiveModel::MissingAttributeError => e
|
23
|
+
restme_scope_errors({ body: model_fields_select, message: e.message })
|
24
|
+
|
25
|
+
restme_scope_status(:bad_request)
|
22
26
|
end
|
23
27
|
|
24
28
|
def select_nested_scope(scoped)
|
data/lib/restme/scope/rules.rb
CHANGED
@@ -22,16 +22,27 @@ module Restme
|
|
22
22
|
include ::Restme::Shared::CurrentModel
|
23
23
|
include ::Restme::Shared::RestmeCurrentUserRole
|
24
24
|
|
25
|
-
attr_reader :
|
25
|
+
attr_reader :filterable_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 ||= begin
|
37
|
+
prepare_model_scope
|
38
|
+
|
39
|
+
restme_scope_errors.presence || restme_pagination_response
|
40
|
+
end
|
30
41
|
end
|
31
42
|
|
32
43
|
def model_scope_object
|
33
44
|
@model_scope_object ||= begin
|
34
|
-
|
45
|
+
prepare_model_scope
|
35
46
|
|
36
47
|
restme_scope_errors.presence || model_scope.first
|
37
48
|
end
|
@@ -39,20 +50,19 @@ module Restme
|
|
39
50
|
|
40
51
|
private
|
41
52
|
|
42
|
-
def
|
43
|
-
|
44
|
-
|
45
|
-
restme_scope_errors.presence || {
|
53
|
+
def restme_pagination_response
|
54
|
+
{
|
46
55
|
objects: model_scope,
|
47
56
|
pagination: pagination
|
48
57
|
}
|
49
58
|
end
|
50
59
|
|
60
|
+
def prepare_model_scope
|
61
|
+
model_scope if any_scope_errors.blank?
|
62
|
+
end
|
63
|
+
|
51
64
|
def any_scope_errors
|
52
|
-
|
53
|
-
unknown_sortable_fields_errors
|
54
|
-
unallowed_filter_fields_errors
|
55
|
-
unallowed_select_fields_errors
|
65
|
+
SCOPE_ERROR_METHODS.each { |m| send(m) }
|
56
66
|
|
57
67
|
restme_scope_errors
|
58
68
|
end
|
@@ -64,8 +74,8 @@ module Restme
|
|
64
74
|
def pagination
|
65
75
|
{
|
66
76
|
page: page_no,
|
67
|
-
pages: pages(
|
68
|
-
total_items: total_items(
|
77
|
+
pages: pages(filterable_scope_response),
|
78
|
+
total_items: total_items(filterable_scope_response)
|
69
79
|
}
|
70
80
|
end
|
71
81
|
|
@@ -80,10 +90,12 @@ module Restme
|
|
80
90
|
end
|
81
91
|
|
82
92
|
def custom_scope
|
83
|
-
@
|
84
|
-
|
85
|
-
|
86
|
-
|
93
|
+
@filterable_scope_response = filterable_scope(user_scope)
|
94
|
+
|
95
|
+
scope = sortable_scope(filterable_scope_response)
|
96
|
+
scope = paginable_scope(scope)
|
97
|
+
|
98
|
+
fieldable_scope(scope)
|
87
99
|
end
|
88
100
|
|
89
101
|
def user_scope
|
data/lib/restme/version.rb
CHANGED