psych 3.3.2 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/psych.rb +53 -60
- data/lib/psych/versions.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: d17b99168b9a2274379d31e2e75b667e8cbe0d4b56cf9bc7dace2e8af07d8c3d
|
4
|
+
data.tar.gz: cf0e77e91cd7f3b9dc4390f1fac70734daad2d747336cf5a4e5e9062035c1f84
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 92813d4ba7e393f2d1800ee7fe77b65cc9f56c6d0cc324440c367a71ef087d9d1a0ce2c3cbddaec238c05f50a205e62b8bd95a2bb88564ba03d729b473a31fcf
|
7
|
+
data.tar.gz: ee68420c75330f9a0671b1e595962fb971940e55b6693d17b41b7b06b8d75c6aa5541625371f3f81e8505c6b7f2d84426dd4fd610b5968e1b17581ca7f5d4bfb
|
data/lib/psych.rb
CHANGED
@@ -234,9 +234,6 @@ require 'psych/class_loader'
|
|
234
234
|
module Psych
|
235
235
|
# The version of libyaml Psych is using
|
236
236
|
LIBYAML_VERSION = Psych.libyaml_version.join('.').freeze
|
237
|
-
# Deprecation guard
|
238
|
-
NOT_GIVEN = Object.new.freeze
|
239
|
-
private_constant :NOT_GIVEN
|
240
237
|
|
241
238
|
###
|
242
239
|
# Load +yaml+ in to a Ruby data structure. If multiple documents are
|
@@ -249,11 +246,11 @@ module Psych
|
|
249
246
|
#
|
250
247
|
# Example:
|
251
248
|
#
|
252
|
-
# Psych.
|
253
|
-
# Psych.
|
249
|
+
# Psych.unsafe_load("--- a") # => 'a'
|
250
|
+
# Psych.unsafe_load("---\n - a\n - b") # => ['a', 'b']
|
254
251
|
#
|
255
252
|
# begin
|
256
|
-
# Psych.
|
253
|
+
# Psych.unsafe_load("--- `", filename: "file.txt")
|
257
254
|
# rescue Psych::SyntaxError => ex
|
258
255
|
# ex.file # => 'file.txt'
|
259
256
|
# ex.message # => "(file.txt): found character that cannot start any token"
|
@@ -262,21 +259,16 @@ module Psych
|
|
262
259
|
# When the optional +symbolize_names+ keyword argument is set to a
|
263
260
|
# true value, returns symbols for keys in Hash objects (default: strings).
|
264
261
|
#
|
265
|
-
# Psych.
|
266
|
-
# Psych.
|
262
|
+
# Psych.unsafe_load("---\n foo: bar") # => {"foo"=>"bar"}
|
263
|
+
# Psych.unsafe_load("---\n foo: bar", symbolize_names: true) # => {:foo=>"bar"}
|
267
264
|
#
|
268
265
|
# Raises a TypeError when `yaml` parameter is NilClass
|
269
266
|
#
|
270
267
|
# NOTE: This method *should not* be used to parse untrusted documents, such as
|
271
268
|
# YAML documents that are supplied via user input. Instead, please use the
|
272
|
-
# safe_load method.
|
269
|
+
# load method or the safe_load method.
|
273
270
|
#
|
274
|
-
def self.unsafe_load yaml,
|
275
|
-
if legacy_filename != NOT_GIVEN
|
276
|
-
warn_with_uplevel 'Passing filename with the 2nd argument of Psych.load is deprecated. Use keyword argument like Psych.load(yaml, filename: ...) instead.', uplevel: 1 if $VERBOSE
|
277
|
-
filename = legacy_filename
|
278
|
-
end
|
279
|
-
|
271
|
+
def self.unsafe_load yaml, filename: nil, fallback: false, symbolize_names: false, freeze: false
|
280
272
|
result = parse(yaml, filename: filename)
|
281
273
|
return fallback unless result
|
282
274
|
result.to_ruby(symbolize_names: symbolize_names, freeze: freeze)
|
@@ -327,27 +319,7 @@ module Psych
|
|
327
319
|
# Psych.safe_load("---\n foo: bar") # => {"foo"=>"bar"}
|
328
320
|
# Psych.safe_load("---\n foo: bar", symbolize_names: true) # => {:foo=>"bar"}
|
329
321
|
#
|
330
|
-
def self.safe_load yaml,
|
331
|
-
if legacy_permitted_classes != NOT_GIVEN
|
332
|
-
warn_with_uplevel 'Passing permitted_classes with the 2nd argument of Psych.safe_load is deprecated. Use keyword argument like Psych.safe_load(yaml, permitted_classes: ...) instead.', uplevel: 1 if $VERBOSE
|
333
|
-
permitted_classes = legacy_permitted_classes
|
334
|
-
end
|
335
|
-
|
336
|
-
if legacy_permitted_symbols != NOT_GIVEN
|
337
|
-
warn_with_uplevel 'Passing permitted_symbols with the 3rd argument of Psych.safe_load is deprecated. Use keyword argument like Psych.safe_load(yaml, permitted_symbols: ...) instead.', uplevel: 1 if $VERBOSE
|
338
|
-
permitted_symbols = legacy_permitted_symbols
|
339
|
-
end
|
340
|
-
|
341
|
-
if legacy_aliases != NOT_GIVEN
|
342
|
-
warn_with_uplevel 'Passing aliases with the 4th argument of Psych.safe_load is deprecated. Use keyword argument like Psych.safe_load(yaml, aliases: ...) instead.', uplevel: 1 if $VERBOSE
|
343
|
-
aliases = legacy_aliases
|
344
|
-
end
|
345
|
-
|
346
|
-
if legacy_filename != NOT_GIVEN
|
347
|
-
warn_with_uplevel 'Passing filename with the 5th argument of Psych.safe_load is deprecated. Use keyword argument like Psych.safe_load(yaml, filename: ...) instead.', uplevel: 1 if $VERBOSE
|
348
|
-
filename = legacy_filename
|
349
|
-
end
|
350
|
-
|
322
|
+
def self.safe_load yaml, permitted_classes: [], permitted_symbols: [], aliases: false, filename: nil, fallback: nil, symbolize_names: false, freeze: false
|
351
323
|
result = parse(yaml, filename: filename)
|
352
324
|
return fallback unless result
|
353
325
|
|
@@ -363,6 +335,46 @@ module Psych
|
|
363
335
|
result
|
364
336
|
end
|
365
337
|
|
338
|
+
###
|
339
|
+
# Load +yaml+ in to a Ruby data structure. If multiple documents are
|
340
|
+
# provided, the object contained in the first document will be returned.
|
341
|
+
# +filename+ will be used in the exception message if any exception
|
342
|
+
# is raised while parsing. If +yaml+ is empty, it returns
|
343
|
+
# the specified +fallback+ return value, which defaults to +false+.
|
344
|
+
#
|
345
|
+
# Raises a Psych::SyntaxError when a YAML syntax error is detected.
|
346
|
+
#
|
347
|
+
# Example:
|
348
|
+
#
|
349
|
+
# Psych.load("--- a") # => 'a'
|
350
|
+
# Psych.load("---\n - a\n - b") # => ['a', 'b']
|
351
|
+
#
|
352
|
+
# begin
|
353
|
+
# Psych.load("--- `", filename: "file.txt")
|
354
|
+
# rescue Psych::SyntaxError => ex
|
355
|
+
# ex.file # => 'file.txt'
|
356
|
+
# ex.message # => "(file.txt): found character that cannot start any token"
|
357
|
+
# end
|
358
|
+
#
|
359
|
+
# When the optional +symbolize_names+ keyword argument is set to a
|
360
|
+
# true value, returns symbols for keys in Hash objects (default: strings).
|
361
|
+
#
|
362
|
+
# Psych.load("---\n foo: bar") # => {"foo"=>"bar"}
|
363
|
+
# Psych.load("---\n foo: bar", symbolize_names: true) # => {:foo=>"bar"}
|
364
|
+
#
|
365
|
+
# Raises a TypeError when `yaml` parameter is NilClass. This method is
|
366
|
+
# similar to `safe_load` except that `Symbol` objects are allowed by default.
|
367
|
+
#
|
368
|
+
def self.load yaml, permitted_classes: [Symbol], permitted_symbols: [], aliases: false, filename: nil, fallback: nil, symbolize_names: false, freeze: false
|
369
|
+
safe_load yaml, permitted_classes: permitted_classes,
|
370
|
+
permitted_symbols: permitted_symbols,
|
371
|
+
aliases: aliases,
|
372
|
+
filename: filename,
|
373
|
+
fallback: fallback,
|
374
|
+
symbolize_names: symbolize_names,
|
375
|
+
freeze: freeze
|
376
|
+
end
|
377
|
+
|
366
378
|
###
|
367
379
|
# Parse a YAML string in +yaml+. Returns the Psych::Nodes::Document.
|
368
380
|
# +filename+ is used in the exception message if a Psych::SyntaxError is
|
@@ -382,22 +394,12 @@ module Psych
|
|
382
394
|
# end
|
383
395
|
#
|
384
396
|
# See Psych::Nodes for more information about YAML AST.
|
385
|
-
def self.parse yaml,
|
386
|
-
if legacy_filename != NOT_GIVEN
|
387
|
-
warn_with_uplevel 'Passing filename with the 2nd argument of Psych.parse is deprecated. Use keyword argument like Psych.parse(yaml, filename: ...) instead.', uplevel: 1 if $VERBOSE
|
388
|
-
filename = legacy_filename
|
389
|
-
end
|
390
|
-
|
397
|
+
def self.parse yaml, filename: nil
|
391
398
|
parse_stream(yaml, filename: filename) do |node|
|
392
399
|
return node
|
393
400
|
end
|
394
401
|
|
395
|
-
|
396
|
-
warn_with_uplevel 'Passing the `fallback` keyword argument of Psych.parse is deprecated.', uplevel: 1 if $VERBOSE
|
397
|
-
fallback
|
398
|
-
else
|
399
|
-
false
|
400
|
-
end
|
402
|
+
false
|
401
403
|
end
|
402
404
|
|
403
405
|
###
|
@@ -446,12 +448,7 @@ module Psych
|
|
446
448
|
# Raises a TypeError when NilClass is passed.
|
447
449
|
#
|
448
450
|
# See Psych::Nodes for more information about YAML AST.
|
449
|
-
def self.parse_stream yaml,
|
450
|
-
if legacy_filename != NOT_GIVEN
|
451
|
-
warn_with_uplevel 'Passing filename with the 2nd argument of Psych.parse_stream is deprecated. Use keyword argument like Psych.parse_stream(yaml, filename: ...) instead.', uplevel: 1 if $VERBOSE
|
452
|
-
filename = legacy_filename
|
453
|
-
end
|
454
|
-
|
451
|
+
def self.parse_stream yaml, filename: nil, &block
|
455
452
|
if block_given?
|
456
453
|
parser = Psych::Parser.new(Handlers::DocumentStream.new(&block))
|
457
454
|
parser.parse yaml, filename
|
@@ -552,12 +549,7 @@ module Psych
|
|
552
549
|
# end
|
553
550
|
# list # => ['foo', 'bar']
|
554
551
|
#
|
555
|
-
def self.load_stream yaml,
|
556
|
-
if legacy_filename != NOT_GIVEN
|
557
|
-
warn_with_uplevel 'Passing filename with the 2nd argument of Psych.load_stream is deprecated. Use keyword argument like Psych.load_stream(yaml, filename: ...) instead.', uplevel: 1 if $VERBOSE
|
558
|
-
filename = legacy_filename
|
559
|
-
end
|
560
|
-
|
552
|
+
def self.load_stream yaml, filename: nil, fallback: [], **kwargs
|
561
553
|
result = if block_given?
|
562
554
|
parse_stream(yaml, filename: filename) do |node|
|
563
555
|
yield node.to_ruby(**kwargs)
|
@@ -595,6 +587,7 @@ module Psych
|
|
595
587
|
self.safe_load f, filename: filename, **kwargs
|
596
588
|
}
|
597
589
|
end
|
590
|
+
class << self; alias load_file safe_load_file end
|
598
591
|
|
599
592
|
# :stopdoc:
|
600
593
|
def self.add_domain_type domain, type_tag, &block
|
data/lib/psych/versions.rb
CHANGED