Sha256: 822b826def3c7480e8e312001f90c2067dd29b2e624493f15e295607936220aa

Contents?: true

Size: 698 Bytes

Versions: 5

Compression:

Stored size: 698 Bytes

Contents

# frozen_string_literal: true

module Porridge
  # {SerializerDefinition} is a class that allows serializers to be defined as with a {SerializerDefiner}, but within
  # a class. Simply subclass this class and use the same DSL within it.
  class SerializerDefinition
    class << self
      attr_writer :definer

      delegate_missing_to :definer

      def inherited(subclass)
        super
        definer.added_serializers.each { |serializer| subclass.definer.serializer(serializer) }
      end

      def definer
        @definer ||= create_definer
      end

      def create_definer
        SerializerDefiner.new
      end

      def reset!
        @definer = nil
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
porridge-0.3.1 lib/porridge/serializer_definition.rb
porridge-0.3.0 lib/porridge/serializer_definition.rb
porridge-0.2.2 lib/porridge/serializer_definition.rb
porridge-0.2.1 lib/porridge/serializer_definition.rb
porridge-0.2.0 lib/porridge/serializer_definition.rb