module KwalifyToJsonSchema::Serialization
Abstract JSON/YAML serialization/deserialization
Public Class Methods
deserialize_from_file(file)
click to toggle source
# File lib/kwalify_to_json_schema/serialization.rb, line 5 def self.deserialize_from_file(file) serialization_for_file(file).deserialize(File.read(file)) end
deserialize_from_string(string, format = "yaml")
click to toggle source
# File lib/kwalify_to_json_schema/serialization.rb, line 13 def self.deserialize_from_string(string, format = "yaml") serialization_for_format(format).deserialize(string) end
serialization_for_file(file)
click to toggle source
@return a Hash giving serialization/deserialization module and methods for a given file extension (.json/.yaml)
# File lib/kwalify_to_json_schema/serialization.rb, line 22 def self.serialization_for_file(file) serialization_for_format(File.extname(file)[1..-1]) end
serialization_for_format(format)
click to toggle source
@return a Hash giving serialization/deserialization module and methods for a format (json/yaml)
# File lib/kwalify_to_json_schema/serialization.rb, line 27 def self.serialization_for_format(format) { "json" => Json, "yaml" => Yaml }[format] || Json end
serialize_to_file(file, object)
click to toggle source
# File lib/kwalify_to_json_schema/serialization.rb, line 9 def self.serialize_to_file(file, object) File.write(file, serialization_for_file(file).serialize(object)) end
serialize_to_string(object, format = "json")
click to toggle source
# File lib/kwalify_to_json_schema/serialization.rb, line 17 def self.serialize_to_string(object, format = "json") serialization_for_format(format).serialize(object) end