class CC::Yaml::Serializer::Json
Constants
- MAP
Public Instance Methods
key_value(key, value, wrapper = "%s")
click to toggle source
# File lib/cc/yaml/serializer/json.rb, line 55 def key_value(key, value, wrapper = "%s") space = pretty? ? " " : "" wrapper % "#{serialize_str(key)}:#{space}#{value}" end
lines(wrapper, lines)
click to toggle source
# File lib/cc/yaml/serializer/json.rb, line 60 def lines(wrapper, lines) return wrapper % lines.join(",") unless pretty? return wrapper % "" if lines.empty? return wrapper % " #{lines.first} " unless lines.size > 1 or lines.first.include?("\n") or lines.first.size > 50 lines = "\n " + lines.join(",\n").strip.gsub("\n", "\n ") + "\n" wrapper % lines end
pretty?()
click to toggle source
# File lib/cc/yaml/serializer/json.rb, line 14 def pretty? !!options[:pretty] end
serialize_binary(value)
click to toggle source
# File lib/cc/yaml/serializer/json.rb, line 39 def serialize_binary(value) raise NotSupportedError, "cannot serialize binary data as JSON" end
serialize_bool(value)
click to toggle source
# File lib/cc/yaml/serializer/json.rb, line 43 def serialize_bool(value) value ? "true" : "false" end
serialize_decrypted(value)
click to toggle source
# File lib/cc/yaml/serializer/json.rb, line 27 def serialize_decrypted(value) serialize_str(value.decrypted_string) end
serialize_encrypted(value)
click to toggle source
# File lib/cc/yaml/serializer/json.rb, line 23 def serialize_encrypted(value) key_value("secure", serialize_str(value.encrypted_string), "{%s}") end
serialize_float(value)
click to toggle source
# File lib/cc/yaml/serializer/json.rb, line 18 def serialize_float(value) raise NotSupportedError, "cannot serialize infinity as JSON" if value.infinite? "#{value}" end
serialize_key(value)
click to toggle source
# File lib/cc/yaml/serializer/json.rb, line 68 def serialize_key(value) value.to_s end
serialize_mapping(node)
click to toggle source
Calls superclass method
CC::Yaml::Serializer::Generic#serialize_mapping
# File lib/cc/yaml/serializer/json.rb, line 47 def serialize_mapping(node) lines("{%s}", super.map { |key, value| key_value(key, value) }) end
serialize_sequence(node)
click to toggle source
Calls superclass method
CC::Yaml::Serializer::Generic#serialize_sequence
# File lib/cc/yaml/serializer/json.rb, line 51 def serialize_sequence(node) lines("[%s]", super) end
serialize_str(value)
click to toggle source
# File lib/cc/yaml/serializer/json.rb, line 31 def serialize_str(value) string = value.encode("utf-8") string.force_encoding("binary") string.gsub!(/["\\\x0-\x1f]/) { MAP[$&] } string.force_encoding("utf-8") "\"#{string}\"" end