Module: Tolk::YAML

Defined in:
lib/tolk/yaml.rb

Constant Summary collapse

SAFE_YAML_OPTIONS =
SafeYAML::Deep.freeze({
  :default_mode => :safe,
  :deserialize_symbols => true
})

Class Method Summary collapse

Class Method Details

.dump(payload) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/tolk/yaml.rb', line 21

def self.dump(payload)
  if payload.respond_to?(:ya2yaml)
    payload.ya2yaml(:syck_compatible => true)
  else
    ::YAML.dump(payload)
  end
end

.load(yaml) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/tolk/yaml.rb', line 8

def self.load(yaml)
  # SafeYAML.load has different arity depending on the YAML engine used.
  if SafeYAML::YAML_ENGINE == "psych"
    SafeYAML.load(yaml, nil, SAFE_YAML_OPTIONS)
  else # syck
    SafeYAML.load(yaml, SAFE_YAML_OPTIONS)
  end
end

.load_file(filename) ⇒ Object



17
18
19
# File 'lib/tolk/yaml.rb', line 17

def self.load_file(filename)
  SafeYAML.load_file(filename, SAFE_YAML_OPTIONS)
end