|
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
|
@@ -271,12 +268,7 @@ module Psych
|
271 | 268 | # YAML documents that are supplied via user input. Instead, please use the
|
272 | 269 | # load method or the safe_load method.
|
273 | 270 | #
|
274 |
| - def self.unsafe_load yaml, legacy_filename = NOT_GIVEN, filename: nil, fallback: false, symbolize_names: false, freeze: false |
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 @@ class << self; alias :load :unsafe_load; end
|
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, legacy_permitted_classes = NOT_GIVEN, legacy_permitted_symbols = NOT_GIVEN, legacy_aliases = NOT_GIVEN, legacy_filename = NOT_GIVEN, permitted_classes: [], permitted_symbols: [], aliases: false, filename: nil, fallback: nil, symbolize_names: false, freeze: false |
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 |
|
@@ -422,22 +394,12 @@ def self.load yaml, permitted_classes: [Symbol], permitted_symbols: [], aliases:
|
422 | 394 | # end
|
423 | 395 | #
|
424 | 396 | # See Psych::Nodes for more information about YAML AST.
|
425 |
| - def self.parse yaml, legacy_filename = NOT_GIVEN, filename: nil, fallback: NOT_GIVEN |
426 |
| - if legacy_filename != NOT_GIVEN |
427 |
| - 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 |
428 |
| - filename = legacy_filename |
429 |
| - end |
430 |
| - |
| 397 | + def self.parse yaml, filename: nil |
431 | 398 | parse_stream(yaml, filename: filename) do |node|
|
432 | 399 | return node
|
433 | 400 | end
|
434 | 401 |
|
435 |
| - if fallback != NOT_GIVEN |
436 |
| - warn_with_uplevel 'Passing the `fallback` keyword argument of Psych.parse is deprecated.', uplevel: 1 if $VERBOSE |
437 |
| - fallback |
438 |
| - else |
439 |
| - false |
440 |
| - end |
| 402 | + false |
441 | 403 | end
|
442 | 404 |
|
443 | 405 | ###
|
@@ -486,12 +448,7 @@ def self.parser
|
486 | 448 | # Raises a TypeError when NilClass is passed.
|
487 | 449 | #
|
488 | 450 | # See Psych::Nodes for more information about YAML AST.
|
489 |
| - def self.parse_stream yaml, legacy_filename = NOT_GIVEN, filename: nil, &block |
490 |
| - if legacy_filename != NOT_GIVEN |
491 |
| - 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 |
492 |
| - filename = legacy_filename |
493 |
| - end |
494 |
| - |
| 451 | + def self.parse_stream yaml, filename: nil, &block |
495 | 452 | if block_given?
|
496 | 453 | parser = Psych::Parser.new(Handlers::DocumentStream.new(&block))
|
497 | 454 | parser.parse yaml, filename
|
@@ -592,12 +549,7 @@ def self.to_json object
|
592 | 549 | # end
|
593 | 550 | # list # => ['foo', 'bar']
|
594 | 551 | #
|
595 |
| - def self.load_stream yaml, legacy_filename = NOT_GIVEN, filename: nil, fallback: [], **kwargs |
596 |
| - if legacy_filename != NOT_GIVEN |
597 |
| - 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 |
598 |
| - filename = legacy_filename |
599 |
| - end |
600 |
| - |
| 552 | + def self.load_stream yaml, filename: nil, fallback: [], **kwargs |
601 | 553 | result = if block_given?
|
602 | 554 | parse_stream(yaml, filename: filename) do |node|
|
603 | 555 | yield node.to_ruby(**kwargs)
|
|
0 commit comments