Module: CoreExtensions::Psych

Defined in:
lib/core_extensions/psych.rb

Overview

Handle the fact that we are loading potentially “unsafe” YAML while still supporting Ruby 2.7 and 3.0.

Instance Method Summary collapse

Instance Method Details

#flexible_load(string) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/core_extensions/psych.rb', line 7

def flexible_load(string)
  load_with = if ::Psych.respond_to?(:unsafe_load)
    :unsafe_load
  else
    :load
  end

  ::Psych.send(load_with, string)
end

#flexible_load_file(path) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/core_extensions/psych.rb', line 17

def flexible_load_file(path)
  load_with = if ::Psych.respond_to?(:unsafe_load_file)
    :unsafe_load_file
  else
    :load_file
  end

  ::Psych.send(load_with, path)
end