eivo-rails-api 0.1.10 → 0.1.14

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 293a3f3bef35b46009f162831c7cac036911d95691acd7663de201201e77cf0b
4
- data.tar.gz: 34cea63eec948fb39809de3556d828f736b88e64a68e5569ea840d04b6fd7263
3
+ metadata.gz: b8362e17aaf35365ac1f318195f53ead6c07f67ae136f5d8330043582f293c5d
4
+ data.tar.gz: 15334f702a62f2f1ca0b8bb44ed28c0b20b74d87e6ef66139564f498abfdd0e0
5
5
  SHA512:
6
- metadata.gz: 9b825140beec644c8b2a3329624dfd6ede68869436fa788b998cd1f45e24388c5bcc5e467330fc587a06589612c39bddd20f80d05552304d6e9a2449a62a9839
7
- data.tar.gz: 882e34dc80ec565cbab69571ad8e27e9f406f1ab33ec0cb193e945e9da6276139851c8b4ca9f8a2c7b1810a32b8bbd8634a4d11bc2c3a2e10f6b11152598957d
6
+ metadata.gz: 0c0941d7283903837f7e051039167872bd3c3ce9f118cd25883556155798373db0d53777ef6efc21d7d71d50635f9224de10d35358060caea7f834a3ff8c6b1a
7
+ data.tar.gz: 8396499cf5728012a59f3c9c4be2afbc53ff2b80250114c0663594230ff47a4376b95b6201fb32b49185cb35c78545ae7c87866139b2c0498b01fe12b02c1099
@@ -5,7 +5,7 @@ module EIVO
5
5
  module Pagination
6
6
  extend ::ActiveSupport::Concern
7
7
 
8
- def paginate(collection)
8
+ def paginate(collection, options = {})
9
9
  unless ::ActiveModel::Type::Boolean.new.cast(params[:pagination]) == false
10
10
  limit = 50
11
11
  if params[:limit]
@@ -22,22 +22,32 @@ module EIVO
22
22
  def pagination_options(collection)
23
23
  options = {
24
24
  is_collection: true,
25
- meta: {
26
- total: collection.total_count,
27
- pages: collection.total_pages
28
- },
29
25
  links: {
30
26
  self: url_for(params.to_unsafe_h.merge(page: collection.current_page)),
31
27
  first: url_for(params.to_unsafe_h.merge(page: 1)),
32
- last: url_for(params.to_unsafe_h.merge(page: collection.total_pages))
33
28
  }
34
29
  }
35
30
 
36
- if !collection.out_of_range? && !collection.first_page?
37
- options[:links][:prev] = url_for(params.to_unsafe_h.merge(page: collection.prev_page))
38
- end
39
- if !collection.out_of_range? && !collection.last_page?
40
- options[:links][:next] = url_for(params.to_unsafe_h.merge(page: collection.next_page))
31
+ # avoid count request on large table
32
+ if params[:pagination] == 'infinite'
33
+ options[:links][:next] = url_for(params.to_unsafe_h.merge(page: collection.current_page + 1))
34
+
35
+ if !collection.first_page?
36
+ options[:links][:prev] = url_for(params.to_unsafe_h.merge(page: collection.current_page - 1))
37
+ end
38
+ else
39
+ options[:links][:last] = url_for(params.to_unsafe_h.merge(page: collection.total_pages))
40
+ options[:meta] = {
41
+ total: collection.total_count,
42
+ pages: collection.total_pages
43
+ }
44
+
45
+ if !collection.out_of_range? && !collection.last_page?
46
+ options[:links][:next] = url_for(params.to_unsafe_h.merge(page: collection.next_page))
47
+ end
48
+ if !collection.out_of_range? && !collection.first_page?
49
+ options[:links][:prev] = url_for(params.to_unsafe_h.merge(page: collection.prev_page))
50
+ end
41
51
  end
42
52
 
43
53
  options
@@ -52,9 +52,11 @@ module EIVO
52
52
  render_errors json_errors.flatten
53
53
  end
54
54
 
55
- def render_error(code, status: :bad_request, source: nil)
55
+ def render_error(code, status: :bad_request, title: nil, detail: nil, source: nil)
56
56
  render_errors([{
57
57
  code: code,
58
+ title: title,
59
+ detail: detail,
58
60
  source: source,
59
61
  status: ::Rack::Utils::SYMBOL_TO_STATUS_CODE[status].to_s
60
62
  }.compact], status: status)
@@ -16,13 +16,14 @@ if Rails.env.staging? || Rails.env.production?
16
16
  config.lograge.ignore_actions = ['EIVO::StatusController#index']
17
17
 
18
18
  config.lograge.custom_options = ->(event) do
19
- result = {
20
- params: event.payload[:params].except('controller', 'action', 'format'),
21
- request_id: event.payload[:request_id]
22
- }
19
+ result = event.payload.dup || {}
23
20
 
24
- result[:user_id] = event.payload[:user_id] if event.payload[:user_id]
25
- result[:organization_id] = event.payload[:organization_id] if event.payload[:organization_id]
21
+ result.delete(:headers)
22
+
23
+ # Removed because already present in event.payload
24
+ if result[:params]
25
+ result[:params] = result[:params].except('controller', 'action', 'format')
26
+ end
26
27
 
27
28
  # https://github.com/roidrage/lograge/pull/307
28
29
  if event.respond_to?(:allocations)
@@ -4,7 +4,7 @@ $LOAD_PATH.push File.expand_path('lib', __dir__)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'eivo-rails-api'
7
- spec.version = '0.1.10'
7
+ spec.version = '0.1.14'
8
8
  spec.authors = ['Jonathan VUKOVICH-TRIBOUHARET']
9
9
  spec.email = ['jonathan@eivo.co']
10
10
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eivo-rails-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.1.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan VUKOVICH-TRIBOUHARET
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-22 00:00:00.000000000 Z
11
+ date: 2021-08-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -218,7 +218,7 @@ homepage: https://www.eivo.co
218
218
  licenses:
219
219
  - MIT
220
220
  metadata: {}
221
- post_install_message:
221
+ post_install_message:
222
222
  rdoc_options: []
223
223
  require_paths:
224
224
  - lib
@@ -234,7 +234,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
234
234
  version: '0'
235
235
  requirements: []
236
236
  rubygems_version: 3.1.2
237
- signing_key:
237
+ signing_key:
238
238
  specification_version: 4
239
239
  summary: EIVO Rails API
240
240
  test_files: []