Sha256: 0af83392d58c22764583796fc6f21453d20dacf10c0cf6c3cb52dbb907ab26b8

Contents?: true

Size: 747 Bytes

Versions: 8

Compression:

Stored size: 747 Bytes

Contents

module Yaks
  module Serializer
    def self.register(format, serializer)
      raise "Serializer for #{format} already registered" if all.key? format
      all[format] = serializer
    end

    def self.all
      @serializers ||= {json: JSONWriter}
    end

    module JSONWriter
      extend Yaks::FP::Callable

      def self.call(data, env)
        JSON.pretty_generate(data)
      end

      def self.transitive?
        true
      end

      def self.inverse
        JSONReader
      end
    end

    module JSONReader
      extend Yaks::FP::Callable

      def self.call(data, env)
        JSON.parse(data)
      end

      def self.transitive?
        true
      end

      def self.inverse
        JSONWriter
      end
    end

  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
yaks-0.9.0 lib/yaks/serializer.rb
yaks-0.8.3 lib/yaks/serializer.rb
yaks-0.8.2 lib/yaks/serializer.rb
yaks-0.8.1 lib/yaks/serializer.rb
yaks-0.8.0 lib/yaks/serializer.rb
yaks-0.8.0.beta2 lib/yaks/serializer.rb
yaks-0.8.0.beta1 lib/yaks/serializer.rb
yaks-0.8.0.alpha lib/yaks/serializer.rb