diff options
author | Koichi ITO <koic.ito@gmail.com> | 2020-01-11 01:30:10 +0900 |
---|---|---|
committer | Koichi ITO <koic.ito@gmail.com> | 2020-01-13 12:46:15 +0900 |
commit | 3e8760652c16912b358af307b55c474d5521ba8f (patch) | |
tree | 0f6567726e4fef32198c4fdce744db4af21b54a8 /lib/hashie | |
parent | b0161f545a9a9e68d3996df21f949b77edb81221 (diff) | |
download | hashie-3e8760652c16912b358af307b55c474d5521ba8f.tar.gz |
Suppress `Psych.safe_load` arg warn when using Psych 3.1.0+
This PR suppresses the following `Psych.safe_load` args warn when using
Psych 3.1.0 (Ruby 2.6+).
```console
% bundle exec rake spec
(snip)
/Users/koic/src/github.com/intridea/hashie/lib/hashie/extensions/parsers/yaml_erb_parser.rb:22:
Passing permitted_classes with the 2nd argument of Psych.safe_load is
deprecated. Use keyword argument like Psych.safe_load(yaml,
permitted_classes: ...) instead.
/Users/koic/src/github.com/intridea/hashie/lib/hashie/extensions/parsers/yaml_erb_parser.rb:22:
Passing permitted_symbols with the 3rd argument of Psych.safe_load is
deprecated. Use keyword argument like Psych.safe_load(yaml,
permitted_symbols: ...) instead.
/Users/koic/src/github.com/intridea/hashie/lib/hashie/extensions/parsers/yaml_erb_parser.rb:22:
Passing aliases with the 4th argument of Psych.safe_load is
deprecated. Use keyword argument like Psych.safe_load(yaml, aliases:
...) instead
```
Diffstat (limited to 'lib/hashie')
-rw-r--r-- | lib/hashie/extensions/parsers/yaml_erb_parser.rb | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/lib/hashie/extensions/parsers/yaml_erb_parser.rb b/lib/hashie/extensions/parsers/yaml_erb_parser.rb index 6a259cb..ed9ae4f 100644 --- a/lib/hashie/extensions/parsers/yaml_erb_parser.rb +++ b/lib/hashie/extensions/parsers/yaml_erb_parser.rb @@ -18,13 +18,30 @@ module Hashie permitted_classes = @options.fetch(:permitted_classes) { [] } permitted_symbols = @options.fetch(:permitted_symbols) { [] } aliases = @options.fetch(:aliases) { true } - # TODO: Psych in newer rubies expects these args to be keyword args. - YAML.safe_load template.result, permitted_classes, permitted_symbols, aliases + + yaml_safe_load(template, permitted_classes, permitted_symbols, aliases) end def self.perform(file_path, options = {}) new(file_path, options).perform end + + private + + if Gem::Version.new(Psych::VERSION) >= Gem::Version.new('3.1.0') # Ruby 2.6+ + def yaml_safe_load(template, permitted_classes, permitted_symbols, aliases) + YAML.safe_load( + template.result, + permitted_classes: permitted_classes, + permitted_symbols: permitted_symbols, + aliases: aliases + ) + end + else + def yaml_safe_load(template, permitted_classes, permitted_symbols, aliases) + YAML.safe_load(template.result, permitted_classes, permitted_symbols, aliases) + end + end end end end |