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
–
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/pathutil/helpers.rb', line 7 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. –
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/pathutil/helpers.rb', line 23 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. –
53 54 55 56 57 58 59 60 61 |
# File 'lib/pathutil/helpers.rb', line 53 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 |