class EacRubyUtils::Yaml
A safe YAML loader/dumper with common types included.
Constants
- DEFAULT_PERMITTED_CLASSES
Public Class Methods
dump(object)
click to toggle source
# File lib/eac_ruby_utils/yaml.rb, line 13 def dump(object) ::YAML.dump(sanitize(object)) end
dump_file(path, object)
click to toggle source
# File lib/eac_ruby_utils/yaml.rb, line 17 def dump_file(path, object) ::File.write(path.to_s, dump(object)) end
load(string)
click to toggle source
# File lib/eac_ruby_utils/yaml.rb, line 21 def load(string) ::YAML.safe_load(string, permitted_classes) end
load_file(path)
click to toggle source
# File lib/eac_ruby_utils/yaml.rb, line 25 def load_file(path) load(::File.read(path.to_s)) end
permitted_classes()
click to toggle source
# File lib/eac_ruby_utils/yaml.rb, line 29 def permitted_classes DEFAULT_PERMITTED_CLASSES end
sanitize(object)
click to toggle source
# File lib/eac_ruby_utils/yaml.rb, line 33 def sanitize(object) Sanitizer.new(object).result end
yaml?(object)
click to toggle source
# File lib/eac_ruby_utils/yaml.rb, line 37 def yaml?(object) return false unless object.is_a?(::String) return false unless object.start_with?('---') load(object) true rescue ::Psych::SyntaxError false end