active_record_api-rest 1.0.19 → 1.0.20

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: 9f7d5bdb3dba9f5d4da9bc806bfe5d3bce9d09149b419c74648481b18840621f
4
- data.tar.gz: '09f75577ff7bc0275d4faea7ae57f9a7103582263702429073fd1217fb8e3636'
3
+ metadata.gz: 164c784fae2fd7add5d47ffc1f6b31bfcc61d66dda43cd5b2bec8273421b8d0a
4
+ data.tar.gz: c1770286f9925be1005f2a1a1bd1237b7f1cba453a93f5a28d755f0386471466
5
5
  SHA512:
6
- metadata.gz: cdfd4c5a8f7b668dd78b24803aa2de4bcb69be77a3d23cf97a80e26b82b5385f779500f8c4a210a57d11716a7cec6901553d1e3054b25b64bc31cda2118779bb
7
- data.tar.gz: af8af57d6ca48745d71cc4add6c32a272bdda6e24b63b34da7c3adec42a2ccfba8b0cb2dde90df0fe330b1777a08c244eeda3d7f7ed7afd4fe8ab3f1b7a92aee
6
+ metadata.gz: 07def8142c96d536e7219d59d1514075fd284f856560cb0064053515f410573c4c1eb9eafc8179e27644cc9d566cf043e8f78b4a92ceac2e6f22188a7e56f000
7
+ data.tar.gz: fd8a436fcc2a0471a2ba6624925304a02ff82a52cc71923091c4e1eed63e4ab7da820371729909a9418d2d8e7e6e812de6ab934817dc6bb539fc794378a7b8a3
@@ -8,9 +8,9 @@ module ActiveRecordApi
8
8
  before_action :validate_params
9
9
 
10
10
  def index
11
- response.headers['x-total'] = @total
11
+ response.headers['x-total'] = models_count
12
12
  response.headers['x-link-next'] = next_url unless next_url.nil?
13
- render json: models.limit(limit), each_serializer: serializer
13
+ render json: models_remaining.limit(limit), each_serializer: serializer
14
14
  end
15
15
 
16
16
  def show
@@ -53,12 +53,19 @@ module ActiveRecordApi
53
53
  @model ||= authorized_models.find_by(id: queryable_params[:id])
54
54
  end
55
55
 
56
- def models
57
- return @models unless @models.nil?
58
- @models = authorized_models.where(queryable_params).order(pagination_param_name => pagination_param_direction)
59
- @total = @models.count
60
- return @models unless pagination_param_value.present?
61
- @models = @models&.where("\"#{pagination_param_name}\" > ?", pagination_param_value)
56
+ def models_full_results
57
+ return @models_full_results unless @models_full_results.nil?
58
+ @models_full_results = authorized_models.where(queryable_params).order(pagination_param_name => pagination_param_direction)
59
+ end
60
+
61
+ def models_count
62
+ @total = models_full_results.count
63
+ end
64
+
65
+ def models_remaining
66
+ return @models_remaining unless @models_remaining.nil?
67
+ @models_remaining = models_full_results&.where("\"#{pagination_param_name}\" > ?", pagination_param_value) if pagination_param_value.present?
68
+ @models_remaining
62
69
  end
63
70
 
64
71
  def initialize_model
@@ -103,9 +110,9 @@ module ActiveRecordApi
103
110
  RequestUrlGenerator.new(
104
111
  action_name: action_name,
105
112
  request: request,
106
- models: models,
113
+ models_remaining: models_remaining,
107
114
  parameters: parameters,
108
- total: @total,
115
+ total_count: models_count,
109
116
  pagination_param_name: pagination_param_name
110
117
  )
111
118
  end
@@ -5,20 +5,20 @@ module ActiveRecordApi
5
5
  include ActiveAttr::Model
6
6
  attribute :request
7
7
  attribute :action_name
8
- attribute :models
8
+ attribute :models_remaining
9
9
  attribute :pagination_param_name
10
10
  attribute :parameters
11
- attribute :count
11
+ attribute :total_count
12
12
  delegate :host_with_port, :path, :query_parameters, to: :request
13
13
  delegate :limit, to: :parameters
14
14
 
15
15
  def next_url
16
- return if count == 0 || models.count <= limit
16
+ return if total_count == 0 || models_remaining.count <= limit
17
17
  "#{current_url}?#{new_params.to_param}"
18
18
  end
19
19
 
20
20
  def new_params
21
- query_parameters.dup.merge(pagination_param_name.to_s => models.limit(limit).last.send(pagination_param_name))
21
+ query_parameters.dup.merge(pagination_param_name.to_s => models_remaining.limit(limit).last.send(pagination_param_name))
22
22
  end
23
23
 
24
24
  def current_url
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ActiveRecordApi
4
4
  module Rest
5
- VERSION = '1.0.19'.freeze
5
+ VERSION = '1.0.20'.freeze
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record_api-rest
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.19
4
+ version: 1.0.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Full Measure Education