sinja 1.1.0.pre2 → 1.1.0.pre3

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
  SHA1:
3
- metadata.gz: d785d25fe6c9bd3e61893ca5a1ec23b237d9e3cb
4
- data.tar.gz: 0eb4c07d1691587fb117ebbfc6d2fb63a911ae81
3
+ metadata.gz: c2b7704d06378c377a7668407ccfe7dd391bf22c
4
+ data.tar.gz: 2a26bd92d8b7357d8561204654030e89398223d3
5
5
  SHA512:
6
- metadata.gz: 0ee40f0a379063b13846967163f181c50ec7c86303155864ecf234369e41faf1d84006c3ac4d07aeff6df13cfcd7ae1010b8055e59b9d0e06d98e666700159aa
7
- data.tar.gz: 6c82ef3fc4fba1670526d5f2aab3fa09ea76921cfe2c8de997f8b13fd52b110fcd45ea34c03bbfaeddc7c43dd76ded5936f71bd5acc1e12f73c47058331e280c
6
+ metadata.gz: c7541478e11cd932871936c7bb470169fafcc4f24133d77c2a8559c5ba5fae07e0f0a5cfd03be94b0efa6222b19cf97f452a14a87300760738fb028b13b58f96
7
+ data.tar.gz: abc9e3d5c75bc8324537f5d5cecad33c61c84eb82f98e2f24ba048fb74de128b5de377f7c272d3078da0dabe9c06578e0827097b358942337636fdbb5dd3d1f9
data/README.md CHANGED
@@ -435,7 +435,7 @@ configure_jsonapi do |c|
435
435
 
436
436
  # You can't set this directly; see "Query Parameters" below
437
437
  #c.query_params = {
438
- # :include=>[], :fields=>{}, :filter=>{}, :page=>{}, :sort=>[]
438
+ # :include=>[], :fields=>{}, :filter=>{}, :page=>{}, :sort=>{}
439
439
  #}
440
440
 
441
441
  #c.page_using = {} # see "Paging" below
@@ -467,7 +467,7 @@ and returns the corresponding object. You can, of course, use this helper
467
467
  method elsewhere in your application, such as in your `show` action helper.
468
468
 
469
469
  ```ruby
470
- resource :posts
470
+ resource :posts do
471
471
  helpers do
472
472
  def find(id)
473
473
  Post[id.to_i]
@@ -908,7 +908,7 @@ parameter(s) in a `before_<action>` hook:
908
908
  resource :posts do
909
909
  helpers do
910
910
  def before_index
911
- params['filter']['type'] ||= 'article'
911
+ params[:filter][:type] = 'article' if params[:filter].empty?
912
912
  end
913
913
  end
914
914
 
@@ -951,7 +951,7 @@ query parameter(s) in a `before_<action>` hook:
951
951
  resource :posts do
952
952
  helpers do
953
953
  def before_index
954
- params['sort'] << [:title, :asc] if params['sort'].empty?
954
+ params[:sort][:title] = :asc if params[:sort].empty?
955
955
  end
956
956
  end
957
957
 
@@ -1009,7 +1009,7 @@ query parameter(s) in a `before_<action>` hook:
1009
1009
  resource :posts do
1010
1010
  helpers do
1011
1011
  def before_index
1012
- params['page']['number'] ||= 1
1012
+ params[:page][:number] = 1 if params[:page].empty?
1013
1013
  end
1014
1014
  end
1015
1015
 
data/lib/sinja/config.rb CHANGED
@@ -59,12 +59,11 @@ module Sinja
59
59
 
60
60
  def initialize
61
61
  @query_params = {
62
- :fields=>{}, # passthru to JAS
63
62
  :include=>[], # passthru to JAS
63
+ :fields=>{}, # passthru to JAS
64
64
  :filter=>{},
65
65
  :page=>{},
66
- :sort=>[],
67
- :capture=>nil
66
+ :sort=>{}
68
67
  }
69
68
 
70
69
  @error_logger = ->(h) { logger.error('sinja') { h } }
data/lib/sinja/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Sinja
3
- VERSION = '1.1.0.pre2'
3
+ VERSION = '1.1.0.pre3'
4
4
  end
data/lib/sinja.rb CHANGED
@@ -104,10 +104,16 @@ module Sinja
104
104
  condition do
105
105
  @qcaptures ||= []
106
106
  index.to_h.all? do |key, subkeys|
107
- params.key?(key.to_s) && [*subkeys].all? do |subkey|
108
- @qcaptures << params[key.to_s].delete(subkey.to_s) \
109
- if params[key.to_s].key?(subkey.to_s)
110
- end
107
+ Hash === params[key.to_s] && params[key.to_s].any? &&
108
+ [*subkeys].all? do |subkey|
109
+ # TODO: What if deleting one is successful, but not another?
110
+ # We'll need to restore the hash to its original state.
111
+ @qcaptures << params[key.to_s].delete(subkey.to_s) \
112
+ if params[key.to_s].key?(subkey.to_s)
113
+ end.tap do |ok|
114
+ # If us deleting key(s) causes the hash to be empty, delete it.
115
+ params.delete(key.to_s) if ok && params[key.to_s].empty?
116
+ end
111
117
  end
112
118
  end
113
119
  end
@@ -122,31 +128,39 @@ module Sinja
122
128
  params.each do |key, value|
123
129
  key = key.to_sym
124
130
 
125
- next if settings._sinja.query_params[key].nil?
131
+ # Ignore interal Sinatra query parameters (e.g. :captures) and any
132
+ # "known" query parameter set to `nil' in the configurable.
133
+ next if !env['rack.request.query_hash'].key?(key.to_s) ||
134
+ settings._sinja.query_params.fetch(key, :_).nil?
126
135
 
127
136
  raise BadRequestError, "`#{key}' query parameter not allowed" \
128
- unless allow_params.include?(key) || value.empty?
137
+ unless allow_params.include?(key)
138
+
139
+ next if env['sinja.normalized'] == params.object_id
129
140
 
130
- if Array === settings._sinja.query_params[key] && String === value
131
- value = (params[key.to_s] = value.split(','))
141
+ if !(String === settings._sinja.query_params[key]) && String === value
142
+ params[key.to_s] = value.split(',')
132
143
  elsif !(settings._sinja.query_params[key].class === value)
133
144
  raise BadRequestError, "`#{key}' query parameter malformed"
134
145
  end
135
146
  end
136
147
 
148
+ return true if env['sinja.normalized'] == params.object_id
149
+
137
150
  settings._sinja.query_params.each do |key, value|
138
151
  next if value.nil?
139
152
 
140
- key = key.to_s
141
-
142
153
  if respond_to?("normalize_#{key}_params")
143
- params[key] = send("normalize_#{key}_params")
154
+ params[key.to_s] = send("normalize_#{key}_params")
144
155
  else
145
- params[key] ||= value
156
+ params[key.to_s] ||= value
146
157
  end
147
158
  end
148
159
 
149
- true
160
+ # Sinatra 2.0 re-initializes `params' at namespace boundaries, but
161
+ # Sinatra 1.4 does not, so we'll reference its object_id in the flag
162
+ # to make sure we only re-normalize the parameters when necessary.
163
+ env['sinja.normalized'] = params.object_id
150
164
  end
151
165
  end
152
166
 
@@ -213,7 +227,7 @@ module Sinja
213
227
  end
214
228
 
215
229
  def normalize_sort_params
216
- return [] unless params[:sort]&.any?
230
+ return {} unless params[:sort]&.any?
217
231
 
218
232
  raise BadRequestError, "Unsupported `sort' query parameter(s)" \
219
233
  unless respond_to?(:sort)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinja
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0.pre2
4
+ version: 1.1.0.pre3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Pastore