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 +4 -4
- data/README.md +5 -5
- data/lib/sinja/config.rb +2 -3
- data/lib/sinja/version.rb +1 -1
- data/lib/sinja.rb +28 -14
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2b7704d06378c377a7668407ccfe7dd391bf22c
|
4
|
+
data.tar.gz: 2a26bd92d8b7357d8561204654030e89398223d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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[
|
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[
|
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[
|
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
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
|
108
|
-
|
109
|
-
if
|
110
|
-
|
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
|
-
|
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)
|
137
|
+
unless allow_params.include?(key)
|
138
|
+
|
139
|
+
next if env['sinja.normalized'] == params.object_id
|
129
140
|
|
130
|
-
if
|
131
|
-
|
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
|
-
|
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
|
230
|
+
return {} unless params[:sort]&.any?
|
217
231
|
|
218
232
|
raise BadRequestError, "Unsupported `sort' query parameter(s)" \
|
219
233
|
unless respond_to?(:sort)
|