restme 1.2.1 → 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: 9a2a5ee870751a00ca5907e773e8d1aaf34fefd68c66bdcbbd42a0809d38ca19
4
- data.tar.gz: 8ef1ff2ab867c127615d53fa903808cc5579f961204cc9ff9306f217f1c7e4ae
3
+ metadata.gz: 1719cb8e1a96b0e12a5015c3eca4c6acfdb3542d6df849f84abdd2aea05a812b
4
+ data.tar.gz: d49bac58ef0983dbbfd4f56710c2b31f8cfe01e1e0d62f886c296b0ea88d98ff
5
5
  SHA512:
6
- metadata.gz: 062df3cf4301fad020426e57ee07eb373ab2751c03f6aed5928e32db4988f8283c4e20254c993515d617dbb4b1e581eae2492aad4aecb0fd2610b0cc38c3afbe
7
- data.tar.gz: ade0cf78bcce6e49a3ecdeb2eb54513c7761c28bce0df20cdd1630bf61393962b68eb9394bdb6eb5e20c9ff04d619ad94932de1a3218ef1578321ca0ecce9fa0
6
+ metadata.gz: e703777e66829853afd8fcb560b2d02e3760249ef604d6af9deb9ee6419dcbd5f34f09589d787a9010fd52ac6b78fc744628e77306635bc5b24f9d0a5ec9ec56
7
+ data.tar.gz: 474185500814429aed08447b12b89cf9a5109b133354b8ba347d01cb1de7cc81d4a23047e4159761ea6ddb120719e6b4ae3c792222c752c9270f589dd39c7313
data/README.md CHANGED
@@ -16,7 +16,7 @@ This gem manages your controller's responsibilities for:
16
16
 
17
17
  GEMFILE:
18
18
  ```bash
19
- gem 'restme', '~> 1.2'
19
+ gem 'restme', '~> 1.2.1'
20
20
  ```
21
21
 
22
22
  INSTALL:
@@ -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)
@@ -22,7 +22,7 @@ module Restme
22
22
  include ::Restme::Shared::CurrentModel
23
23
  include ::Restme::Shared::RestmeCurrentUserRole
24
24
 
25
- attr_reader :sortable_scope_response, :paginable_scope_response
25
+ attr_reader :filterable_scope_response
26
26
  attr_writer :restme_scope_errors, :restme_scope_status
27
27
 
28
28
  SCOPE_ERROR_METHODS = %i[
@@ -33,12 +33,16 @@ module Restme
33
33
  ].freeze
34
34
 
35
35
  def pagination_response
36
- @pagination_response ||= restme_pagination_response
36
+ @pagination_response ||= begin
37
+ prepare_model_scope
38
+
39
+ restme_scope_errors.presence || restme_pagination_response
40
+ end
37
41
  end
38
42
 
39
43
  def model_scope_object
40
44
  @model_scope_object ||= begin
41
- model_scope unless any_scope_errors.present?
45
+ prepare_model_scope
42
46
 
43
47
  restme_scope_errors.presence || model_scope.first
44
48
  end
@@ -47,14 +51,16 @@ module Restme
47
51
  private
48
52
 
49
53
  def restme_pagination_response
50
- any_scope_errors
51
-
52
- restme_scope_errors.presence || {
54
+ {
53
55
  objects: model_scope,
54
56
  pagination: pagination
55
57
  }
56
58
  end
57
59
 
60
+ def prepare_model_scope
61
+ model_scope if any_scope_errors.blank?
62
+ end
63
+
58
64
  def any_scope_errors
59
65
  SCOPE_ERROR_METHODS.each { |m| send(m) }
60
66
 
@@ -84,16 +90,12 @@ module Restme
84
90
  end
85
91
 
86
92
  def custom_scope
87
- return filterable_scope_response if filterable_scope_response.blank?
93
+ @filterable_scope_response = filterable_scope(user_scope)
88
94
 
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
95
+ scope = sortable_scope(filterable_scope_response)
96
+ scope = paginable_scope(scope)
94
97
 
95
- def filterable_scope_response
96
- @filterable_scope_response ||= filterable_scope(user_scope)
98
+ fieldable_scope(scope)
97
99
  end
98
100
 
99
101
  def user_scope
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Restme
4
- VERSION = "1.2.1"
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.1
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - everson-ever