Module: Bootsnap::CompileCache::YAML::Psych4::SafeLoad

Extended by:
SafeLoad
Included in:
SafeLoad
Defined in:
lib/bootsnap/compile_cache/yaml.rb

Instance Method Summary collapse

Instance Method Details

#input_to_output(data, _path, kwargs) ⇒ Object



265
266
267
# File 'lib/bootsnap/compile_cache/yaml.rb', line 265

def input_to_output(data, _path, kwargs)
  ::YAML.load(data, **(kwargs || {}))
end

#input_to_storage(contents, _) ⇒ Object



235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
# File 'lib/bootsnap/compile_cache/yaml.rb', line 235

def input_to_storage(contents, _)
  obj = begin
    CompileCache::YAML.strict_load(contents)
  rescue Psych::DisallowedClass, Psych::BadAlias, Uncompilable
    return UNCOMPILABLE
  end

  packer = CompileCache::YAML.msgpack_factory.packer
  packer.pack(true) # safe loaded
  begin
    packer.pack(obj)
  rescue NoMethodError, RangeError
    return UNCOMPILABLE
  end
  packer.to_s
end

#storage_to_output(data, kwargs) ⇒ Object



252
253
254
255
256
257
258
259
260
261
262
263
# File 'lib/bootsnap/compile_cache/yaml.rb', line 252

def storage_to_output(data, kwargs)
  unpacker = CompileCache::YAML.msgpack_factory.unpacker(
    CompileCache::YAML.msgpack_unpacker_options(kwargs),
  )
  unpacker.feed(data)
  safe_loaded = unpacker.unpack
  if safe_loaded
    unpacker.unpack
  else
    UNCOMPILABLE
  end
end