toast 1.0.11 → 1.0.12

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
  SHA1:
3
- metadata.gz: b91449bc966996f84da87e01c7788088fb429ef4
4
- data.tar.gz: b0986f54a342b73fb228aae8cd5b2ceb27e5e322
3
+ metadata.gz: ef2a1167b071463b05602eafb1512b3e3ec8ad16
4
+ data.tar.gz: 49aff897ffcca410526d3ad99a932f71223dfcec
5
5
  SHA512:
6
- metadata.gz: de5754881ff246d16513363a307f36b3a65a4dddbc46dae44083fc245d240dbaaf2ffa28ef2cfeb15686946272a062e5e0627b8d7f961ad4583ead50211fb207
7
- data.tar.gz: 1b59e4a0a096db8bf621eb3448651322de390c9fe25746d8ee397cff1312ac6f127c7ab06cdf06099c391db411e4c91985501f747b97b84c57c0f82353cf2eea
6
+ metadata.gz: 9119ba7f10a88228e1a88c11a313e1cfb9c3308c6d665c36b67adc0fe0595b87042320b6464820733dbe087c16b1eb1f1b4d6b37e80c07edc2bf3ba2b7084277
7
+ data.tar.gz: 7dc4fd2e26e3a3aefc19930244d1dcf15b4be3856757a2c3ce992c00671ea07d55e19b8afadcd2d2b1177ea128a8267da549eaa8b6056eac787a628a4bc6e4b1
@@ -51,6 +51,8 @@ class Toast::CollectionRequest
51
51
  if relation.is_a?(ActiveRecord::Relation) and
52
52
  relation.model == @config.base_model_class
53
53
 
54
+ result = relation.limit(window).offset(range_start)
55
+
54
56
  # count = relation.count doesn't always work
55
57
  # fix problematic select extensions for counting (-> { select(...) })
56
58
  # this fails if the where clause depends on the the extended select
@@ -58,19 +60,13 @@ class Toast::CollectionRequest
58
60
  headers = {"Content-Type" => @config.media_type}
59
61
 
60
62
  if count > 0
61
- range_end = if (range_start + window - 1) > (count - 1) # behind last
62
- count - 1
63
- else
64
- (range_start + window - 1)
65
- end
66
-
67
- headers[ "Content-Range"] = "items=#{range_start}-#{range_end}/#{count}"
63
+ headers["Content-Range"] = "items=#{range_start}-#{range_start + result.length - 1}/#{count}"
68
64
  end
69
65
 
70
66
  response :ok,
71
67
  headers: headers,
72
- body: represent(relation.limit(window).offset(range_start), @base_config),
73
- msg: "sent #{count} of #{@config.mode_class}"
68
+ body: represent(result, @base_config),
69
+ msg: "sent #{result.length} records of #{@base_config.model_class}"
74
70
 
75
71
  else
76
72
  # wrong class/model_class
@@ -60,6 +60,8 @@ class Toast::PluralAssocRequest
60
60
 
61
61
  call_allow(@config.via_get.permissions, @auth, source, @uri_params) # may raise NotAllowed, AllowError
62
62
 
63
+ result = relation.limit(window).offset(range_start)
64
+
63
65
  # count = relation.count doesn't always work
64
66
  # fix problematic select extensions for counting (-> { select(...) })
65
67
  # this fails if the where clause depends on the the extended select
@@ -70,19 +72,13 @@ class Toast::PluralAssocRequest
70
72
  headers = {"Content-Type" => @config.media_type}
71
73
 
72
74
  if count > 0
73
- range_end = if (range_start + window - 1) > (count - 1) # behind last
74
- count - 1
75
- else
76
- (range_start + window - 1)
77
- end
78
-
79
- headers[ "Content-Range"] = "items=#{range_start}-#{range_end}/#{count}"
75
+ headers["Content-Range"] = "items=#{range_start}-#{range_start + result.length - 1}/#{count}"
80
76
  end
81
77
 
82
78
  response :ok,
83
79
  headers: headers,
84
- body: represent(relation.limit(window).offset(range_start), target_config),
85
- msg: "sent #{count} of #{target_config.model_class}"
80
+ body: represent(result, target_config),
81
+ msg: "sent #{result.length} records of #{target_config.model_class}"
86
82
 
87
83
 
88
84
  rescue ActiveRecord::RecordNotFound
@@ -90,7 +90,7 @@ module Toast::RequestHelpers
90
90
  #
91
91
  # Return: Rack conform response
92
92
  def response status_sym, headers: {}, msg: nil, body: nil
93
- Toast.logger.info "[#{Thread.current.object_id}] done: #{msg}"
93
+ Toast.logger.info "[#{Thread.current.object_id}] done: #{msg}"
94
94
 
95
95
  unless Rails.env == 'production'
96
96
  # put message in body, too, if body is free
@@ -1,3 +1,3 @@
1
1
  module Toast
2
- VERSION = '1.0.11'
2
+ VERSION = '1.0.12'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: toast
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.11
4
+ version: 1.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - robokopp (Robert Annies)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-29 00:00:00.000000000 Z
11
+ date: 2019-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails