diff options
author | Aaron Patterson <tenderlove@ruby-lang.org> | 2020-09-10 08:56:37 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-10 08:56:37 -0700 |
commit | 011dd50a19c8c2af2063fdc0f9b323eae1659af3 (patch) | |
tree | 40b883934477fd208f7f78f52e845a87fe90927f /lib/psych.rb | |
parent | 181a727c90cb1d320db5821bc16dc0bc34757935 (diff) | |
parent | 4e1dd37f09132ddd4f954b95bce64c37a8f6a9ec (diff) | |
download | psych-011dd50a19c8c2af2063fdc0f9b323eae1659af3.zip |
Merge pull request #463 from Shopify/load-file-options
Forward keyword arguments in load_file and load_stream
Diffstat (limited to 'lib/psych.rb')
-rw-r--r-- | lib/psych.rb | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/lib/psych.rb b/lib/psych.rb index 3fc98db..b09866a 100644 --- a/lib/psych.rb +++ b/lib/psych.rb @@ -549,7 +549,7 @@ module Psych # end # list # => ['foo', 'bar'] # - def self.load_stream yaml, legacy_filename = NOT_GIVEN, filename: nil, fallback: [] + def self.load_stream yaml, legacy_filename = NOT_GIVEN, filename: nil, fallback: [], **kwargs if legacy_filename != NOT_GIVEN 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 filename = legacy_filename @@ -557,10 +557,10 @@ module Psych result = if block_given? parse_stream(yaml, filename: filename) do |node| - yield node.to_ruby + yield node.to_ruby(**kwargs) end else - parse_stream(yaml, filename: filename).children.map(&:to_ruby) + parse_stream(yaml, filename: filename).children.map { |node| node.to_ruby(**kwargs) } end return fallback if result.is_a?(Array) && result.empty? @@ -571,9 +571,9 @@ module Psych # Load the document contained in +filename+. Returns the yaml contained in # +filename+ as a Ruby object, or if the file is empty, it returns # the specified +fallback+ return value, which defaults to +false+. - def self.load_file filename, fallback: false + def self.load_file filename, **kwargs File.open(filename, 'r:bom|utf-8') { |f| - self.load f, filename: filename, fallback: fallback + self.load f, filename: filename, **kwargs } end |