Class: EacRubyUtils::Yaml
Overview
A safe YAML loader/dumper with common types included.
Defined Under Namespace
Classes: Sanitizer
Constant Summary collapse
- DEFAULT_PERMITTED_CLASSES =
[::Array, ::Date, ::DateTime, ::FalseClass, ::Hash, ::NilClass, ::Numeric, ::String, ::Symbol, ::Time, ::TrueClass].freeze
Class Method Summary collapse
- .dump(object) ⇒ Object
- .dump_file(path, object) ⇒ Object
- .load(string) ⇒ Object
- .load_file(path) ⇒ Object
- .permitted_classes ⇒ Object
- .sanitize(object) ⇒ Object
- .yaml?(object) ⇒ Boolean
Class Method Details
.dump(object) ⇒ Object
13 14 15 |
# File 'lib/eac_ruby_utils/yaml.rb', line 13 def dump(object) ::YAML.dump(sanitize(object)) end |
.dump_file(path, object) ⇒ Object
17 18 19 |
# File 'lib/eac_ruby_utils/yaml.rb', line 17 def dump_file(path, object) ::File.write(path.to_s, dump(object)) end |
.load(string) ⇒ Object
21 22 23 |
# File 'lib/eac_ruby_utils/yaml.rb', line 21 def load(string) ::YAML.safe_load(string, permitted_classes) end |
.load_file(path) ⇒ Object
25 26 27 |
# File 'lib/eac_ruby_utils/yaml.rb', line 25 def load_file(path) load(::File.read(path.to_s)) end |
.permitted_classes ⇒ Object
29 30 31 |
# File 'lib/eac_ruby_utils/yaml.rb', line 29 def permitted_classes DEFAULT_PERMITTED_CLASSES end |