Module: Pathutil::Helpers
Instance Method Summary collapse
-
#allowed ⇒ Object
--.
-
#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
#allowed ⇒ Object
--
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/pathutil/helpers.rb', line 11 def allowed return @allowed ||= begin { :yaml => { :classes => [], :symbols => [] } } end end |
#load_yaml(data, safe: true, whitelist_classes: , whitelist_symbols: , aliases: :yes) ⇒ Object
Note:
We default aliases to yes so we can detect if you explicit true.
--
Wraps around YAML and SafeYAML to provide alternatives to Rubies.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/pathutil/helpers.rb', line 27 def load_yaml(data, safe: true, whitelist_classes: allowed[:yaml][:classes], \ whitelist_symbols: allowed[:yaml][: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.
57 58 59 60 61 62 63 64 65 |
# File 'lib/pathutil/helpers.rb', line 57 def make_tmpname(prefix = "", suffix = nil, root = nil) prefix = tmpname_prefix(prefix) suffix = tmpname_suffix(suffix) root ||= Dir::Tmpname.tmpdir File.join(root, __make_tmpname( prefix, suffix )) end |