# Formats decide how a thing is encoded over the wire, regardless of what # transport protocol is used. So, if you want to send protobufs over HTTP go # nuts, dude. module Servicy # This represents an abstract class that should be overwritten for individual # formats. class Format class << self # @param [Hash] things is a key-value pairing where the values are the # things to be encoded. You can call this recursively for nested objects. def format(things) raise NotImplementedError.new end # Turn a formatted thing back into a native representation def unformat(thing) raise NotImplementedError.new end end end module Formats def self.method_missing(name, *args, &block) c = Servicy::Formats.const_get(name) return c if c && c.ancestors.include?(Servicy::Format) rescue super end end end # Load all the formatters Dir[File.expand_path(File.join(File.dirname(__FILE__), 'formats', '*.rb'))].each do |file| next if file.start_with?('.') || File.directory?(file) require File.expand_path(file) end