Sha256: c1460652070833ae5d2a511883dceeeff67181ea094e45be6ba89f7f12784cec

Contents?: true

Size: 1.09 KB

Versions: 2

Compression:

Stored size: 1.09 KB

Contents

# 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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
servicy-0.0.6 lib/formats.rb
servicy-0.0.5 lib/formats.rb