Module: Pathutil::Helpers
Instance Method Summary collapse
-
#load_yaml(data, safe: true, whitelist_classes: [], whitelist_symbols: [], aliases: :yes) ⇒ Object
———————————————————————— Wraps around YAML and SafeYAML to provide alternatives to Rubies.
-
#make_tmpname(prefix = "", suffix = nil, root = nil) ⇒ Object
———————————————————————— Make a temporary name suitable for temporary files and directories.
Instance Method Details
#load_yaml(data, safe: true, whitelist_classes: [], whitelist_symbols: [], aliases: :yes) ⇒ Object
Wraps around YAML and SafeYAML to provide alternatives to Rubies. Note: We default aliases to yes so we can detect if you explicit true.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/pathutil/helpers.rb', line 10 def load_yaml(data, safe: true, whitelist_classes: [], whitelist_symbols: [], aliases: :yes) require "yaml" unless safe return YAML.load( data ) end if !YAML.respond_to?(:safe_load) setup_safe_yaml whitelist_classes, aliases SafeYAML.load( data ) else YAML.safe_load( data, whitelist_classes, whitelist_symbols, aliases ) end end |
#make_tmpname(prefix = "", suffix = nil, root = nil) ⇒ Object
Make a temporary name suitable for temporary files and directories.
39 40 41 42 43 44 45 46 47 |
# File 'lib/pathutil/helpers.rb', line 39 def make_tmpname(prefix = "", suffix = nil, root = nil) prefix = tmpname_prefix(prefix) suffix = tmpname_suffix(suffix) root ||= Dir::Tmpname.tmpdir File.join(root, Dir::Tmpname.make_tmpname( prefix, suffix )) end |