spaceborne 0.1.37 → 0.1.38
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/spaceborne.rb +33 -20
- data/lib/spaceborne/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d742ea06ad022126a7a61fb008131b02d0f0f1db485d832570b85f845299c655
|
4
|
+
data.tar.gz: d7d452c83c164adebc69df71aef6aa2f12d50375be2e354463f7b7789b07c290
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e16b9d1bc60eabc5257afb91510d4a715bd8ce76acccc820a255a96ad4b19f87732360d98e3dfbfcfd0f53bd2d7524a72868602df29b2bc5fa871a15128e40e
|
7
|
+
data.tar.gz: 0bac75438755e532b9d39c10864d91430d9a7d281f7d89b9ee1d1943ab7951381432fb0e48ccd39bbc95725dafb8db93a99ba4edc9a53eebec3d6c4bc8e15e59
|
data/lib/spaceborne.rb
CHANGED
@@ -156,6 +156,22 @@ module Airborne
|
|
156
156
|
|
157
157
|
# Extend airborne's expectations
|
158
158
|
module RequestExpectations
|
159
|
+
class OptionalPathExpectations
|
160
|
+
def initialize(string)
|
161
|
+
@string = string
|
162
|
+
end
|
163
|
+
def to_s
|
164
|
+
@string.to_s
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
def do_process_json(part, json)
|
169
|
+
json = process_json(part, json)
|
170
|
+
rescue StandardError
|
171
|
+
raise PathError,
|
172
|
+
"Expected #{json.class}\nto be an object with property #{part}"
|
173
|
+
end
|
174
|
+
|
159
175
|
def call_with_relative_path(data, args)
|
160
176
|
if args.length == 2
|
161
177
|
get_by_path(args[0], data) do |json_chunk|
|
@@ -204,17 +220,18 @@ module Airborne
|
|
204
220
|
end
|
205
221
|
end
|
206
222
|
end
|
223
|
+
|
224
|
+
def optional(data)
|
225
|
+
if data.is_a?(Hash)
|
226
|
+
OptionalHashTypeExpectations.new(data)
|
227
|
+
else
|
228
|
+
OptionalPathExpectations.new(data)
|
229
|
+
end
|
230
|
+
end
|
207
231
|
end
|
208
232
|
|
209
233
|
# extension to handle hash value checking
|
210
234
|
module PathMatcher
|
211
|
-
def do_process_json(part, json)
|
212
|
-
json = process_json(part, json)
|
213
|
-
rescue StandardError
|
214
|
-
raise PathError,
|
215
|
-
"Expected #{json.class}\nto be an object with property #{part}"
|
216
|
-
end
|
217
|
-
|
218
235
|
def handle_container(json, &block)
|
219
236
|
case json.class.name
|
220
237
|
when 'Array'
|
@@ -237,38 +254,34 @@ module Airborne
|
|
237
254
|
end
|
238
255
|
end
|
239
256
|
|
240
|
-
def
|
241
|
-
path.is_a?(Airborne::
|
242
|
-
|
243
|
-
|
244
|
-
def make_path_optional(path, sub_path)
|
245
|
-
if path.is_a?(Airborne::OptionalHashTypeExpectations)
|
246
|
-
Airborne::OptionalHashTypeExpectations.new(sub_path)
|
257
|
+
def make_sub_path_optional(path, sub_path)
|
258
|
+
if path.is_a?(Airborne::OptionalPathExpectations)
|
259
|
+
Airborne::OptionalPathExpectations.new(sub_path)
|
247
260
|
else
|
248
261
|
sub_path
|
249
262
|
end
|
250
263
|
end
|
251
264
|
|
252
265
|
def iterate_path(path)
|
253
|
-
raise PathError, "Invalid Path, contains '..'" if /\.\./ =~
|
266
|
+
raise PathError, "Invalid Path, contains '..'" if /\.\./ =~ path.to_s
|
254
267
|
|
255
|
-
parts =
|
268
|
+
parts = path.to_s.split('.')
|
256
269
|
parts.each_with_index do |part, index|
|
257
|
-
use_part =
|
270
|
+
use_part = make_sub_path_optional(path, part)
|
258
271
|
yield(parts, use_part, index)
|
259
272
|
end
|
260
273
|
end
|
261
274
|
|
262
275
|
def get_by_path(path, json, type: false, &block)
|
263
276
|
iterate_path(path) do |parts, part, index|
|
264
|
-
if %w[* ?].include?(
|
277
|
+
if %w[* ?].include?(part.to_s)
|
265
278
|
ensure_array_or_hash(path, json)
|
266
279
|
type = part
|
267
280
|
walk_with_path(type, index, path, parts, json, &block) && return if index < parts.length.pred
|
268
281
|
|
269
282
|
next
|
270
283
|
end
|
271
|
-
json = do_process_json(
|
284
|
+
json = do_process_json(part.to_s, json)
|
272
285
|
end
|
273
286
|
handle_type(type, path, json, &block)
|
274
287
|
end
|
@@ -288,7 +301,7 @@ module Airborne
|
|
288
301
|
json.each do |element|
|
289
302
|
begin
|
290
303
|
sub_path = parts[(index.next)...(parts.length)].join('.')
|
291
|
-
get_by_path(
|
304
|
+
get_by_path(make_sub_path_optional(path, sub_path), element, &block)
|
292
305
|
rescue Exception => e
|
293
306
|
last_error = e
|
294
307
|
error_count += 1
|
data/lib/spaceborne/version.rb
CHANGED