restme 0.0.37 → 0.0.38
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 +2 -3
- data/lib/restme/scope/filter/rules.rb +28 -15
- data/lib/restme/scope/paginate/rules.rb +3 -1
- 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: 65794fd40e07c3dad593d15b93cbdfd860dfed7dbc4efcf960c410eedc9bd7ec
|
4
|
+
data.tar.gz: d688961f322dc7caabc5e6c7c28e362a237097e7fababbcf7f3c40bf45cd8582
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c67210649fc7511aa4150f14fbf262c76357d667c05c541fe7f0850c8ca7570f6c503d98f6109ffc5ef15be34b875d23a120b528c6c4edce73e1b620c032099
|
7
|
+
data.tar.gz: 1a6eb52d9fbe9f2d6c4b568f4b6d80ee12f22693698bd993b9175c09f946ef4943b063b218a6a1f5aeb868f86c6e25ca47aa0898a4c4fdca67542bf57c1c6633
|
data/README.md
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
# Restme
|
2
2
|
|
3
|
-
## ⚠️ Do not use this gem yet. In progress
|
4
|
-
|
5
3
|
[](https://badge.fury.io/rb/restme)
|
6
4
|
|
7
5
|
Adds support for new **Rails** controller actions such as pagination, filtering, sorting, and selecting specific model fields. Easily implement full CRUD functionality by importing Restme into your controller.
|
@@ -21,7 +19,7 @@ gem install restme
|
|
21
19
|
OR
|
22
20
|
|
23
21
|
```bash
|
24
|
-
gem 'restme', '~> 0.0.
|
22
|
+
gem 'restme', '~> 0.0.37'
|
25
23
|
```
|
26
24
|
|
27
25
|
## Usage
|
@@ -36,6 +34,7 @@ gem 'restme', '~> 0.0.33'
|
|
36
34
|
|
37
35
|
### Usage examples
|
38
36
|
|
37
|
+
Rails API project example here: https://github.com/everson-ever/restme-example/pull/1
|
39
38
|
|
40
39
|
#### First of all
|
41
40
|
|
@@ -23,14 +23,21 @@ module Restme
|
|
23
23
|
|
24
24
|
ID = :id
|
25
25
|
|
26
|
-
FILTERS_TYPES = %i[
|
27
|
-
|
26
|
+
FILTERS_TYPES = %i[
|
27
|
+
equal
|
28
|
+
like
|
29
|
+
bigger_than
|
30
|
+
less_than
|
31
|
+
bigger_than_or_equal_to
|
32
|
+
less_than_or_equal_to
|
33
|
+
in
|
34
|
+
].freeze
|
28
35
|
|
29
36
|
private
|
30
37
|
|
31
38
|
def filterable_scope(user_scope)
|
32
|
-
return unallowed_filter_fields_response if unallowed_fields_to_filter?
|
33
39
|
return user_scope unless filterable_scope?
|
40
|
+
return user_scope if unallowed_filter_fields_errors
|
34
41
|
|
35
42
|
next_scope = where_equal(user_scope)
|
36
43
|
next_scope = where_like(next_scope)
|
@@ -66,29 +73,35 @@ module Restme
|
|
66
73
|
[ID]
|
67
74
|
end
|
68
75
|
|
69
|
-
def
|
76
|
+
def filterable_scope?
|
70
77
|
try_insert_id_equal
|
71
78
|
|
72
|
-
filterable_scope? && unallowed_fields_to_filter.present?
|
73
|
-
end
|
74
|
-
|
75
|
-
def filterable_scope?
|
76
79
|
request.get? && controller_params_filters_fields.present?
|
77
80
|
end
|
78
81
|
|
79
|
-
def unallowed_fields_to_filter
|
80
|
-
@unallowed_fields_to_filter ||= controller_params_filters_fields - allowed_fields
|
81
|
-
end
|
82
|
-
|
83
82
|
def try_insert_id_equal
|
84
83
|
return if params[:id].blank?
|
85
84
|
|
86
85
|
controller_params_filters_fields.push(:id_equal)
|
87
86
|
end
|
88
87
|
|
89
|
-
def
|
90
|
-
|
91
|
-
|
88
|
+
def unallowed_filter_fields_errors
|
89
|
+
return unless unallowed_fields_to_filter.present?
|
90
|
+
|
91
|
+
restme_scope_errors(
|
92
|
+
{
|
93
|
+
message: "Unknown Filter Fields",
|
94
|
+
body: unallowed_fields_to_filter
|
95
|
+
}
|
96
|
+
)
|
97
|
+
|
98
|
+
restme_scope_status(:bad_request)
|
99
|
+
|
100
|
+
true
|
101
|
+
end
|
102
|
+
|
103
|
+
def unallowed_fields_to_filter
|
104
|
+
@unallowed_fields_to_filter ||= controller_params_filters_fields - allowed_fields
|
92
105
|
end
|
93
106
|
|
94
107
|
def controller_params_filters_fields
|
@@ -10,7 +10,7 @@ module Restme
|
|
10
10
|
MAX_PER_PAGE = ENV.fetch("PAGINATION_MAX_PER_PAGE", 100)
|
11
11
|
|
12
12
|
def paginable_scope(user_scope)
|
13
|
-
per_page_error
|
13
|
+
return user_scope if per_page_error
|
14
14
|
|
15
15
|
user_scope.limit(per_page).offset(paginate_offset)
|
16
16
|
end
|
@@ -46,6 +46,8 @@ module Restme
|
|
46
46
|
)
|
47
47
|
|
48
48
|
restme_scope_status(:bad_request)
|
49
|
+
|
50
|
+
true
|
49
51
|
end
|
50
52
|
end
|
51
53
|
end
|
data/lib/restme/version.rb
CHANGED