Sha256: b38733331fd2757070a5c2ce46162eb28c208a929e11b5ab8ca9768c8da3b7fe

Contents?: true

Size: 689 Bytes

Versions: 3

Compression:

Stored size: 689 Bytes

Contents

# frozen_string_literal: true

module AdequateSerialization
  class Serializer
    class << self
      def attributes
        @attributes ||= []
      end

      def attribute(*names, &block)
        options =
          if names.last.is_a?(Hash)
            names.pop
          else
            {}
          end

        additions =
          names.map! { |name| Attribute.from(name, options.dup, &block) }

        @attributes = attributes + additions
      end
    end

    def serialize(model, opts = Options.null)
      self.class.attributes.each_with_object({}) do |attribute, response|
        attribute.serialize_to(self, response, model, opts.includes)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
adequate_serialization-1.0.0 lib/adequate_serialization/serializer.rb
adequate_serialization-0.1.1 lib/adequate_serialization/serializer.rb
adequate_serialization-0.1.0 lib/adequate_serialization/serializer.rb