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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0f3c9d79dc88d267a1198ec23b54f05d8af00367125b1cf1f3fcd6c458633b35
4
- data.tar.gz: 48c79f664b0fb61dea85fdd4d2d56d63520f7389c6b31adbead1c41a6b945268
3
+ metadata.gz: 1719cb8e1a96b0e12a5015c3eca4c6acfdb3542d6df849f84abdd2aea05a812b
4
+ data.tar.gz: d49bac58ef0983dbbfd4f56710c2b31f8cfe01e1e0d62f886c296b0ea88d98ff
5
5
  SHA512:
6
- metadata.gz: 80455f1ab99ddec14145d9ed3229c491abfd48c1d2db0fae6532d56ca3304783749d2cba38216ef6529ed6a2985743ed41c3feb2e3fb72273eb8c1a87eae332a
7
- data.tar.gz: e7033c0ded95c20fb3df221af86dff3801a67c80cd7b9f3ac4d070f4f64b979d385e01874bbceccdf0affac556752261ffc24e22acd485651d9163650083f8c8
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
- 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>
@@ -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)
@@ -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,16 +22,27 @@ 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 :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 ||= restme_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
- model_scope unless any_scope_errors.present?
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 restme_response
43
- any_scope_errors
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
- per_page_errors
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(filtered_scope),
68
- total_items: total_items(filtered_scope)
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
- @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)
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
@@ -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.2"
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.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - everson-ever