Sha256: c0f1aeee1e1f337d60997b91e07be4dbd91c647eaa1fec75ff264d3eb7dd5123

Contents?: true

Size: 679 Bytes

Versions: 2

Compression:

Stored size: 679 Bytes

Contents

require 'ivy/serializers/mapping'

module Ivy
  module Serializers
    class Registry
      def initialize
        @mappings = Hash.new { |hash, klass| hash[klass] = new_mapping(klass) }
      end

      def links(generator, resource)
        mapping_for(resource.class).links(generator, resource)
      end

      def map(klass, &block)
        mapping_for(klass).instance_eval(&block)
      end

      def resource(generator, resource)
        mapping_for(resource.class).resource(generator, resource)
      end

      private

      def mapping_for(klass)
        @mappings[klass]
      end

      def new_mapping(klass)
        Mapping.new(klass)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ivy-serializers-0.2.0 lib/ivy/serializers/registry.rb
ivy-serializers-0.1.0 lib/ivy/serializers/registry.rb