Sha256: f0a214a76b3526b357924b706a5b1a7cd259e30afc1d0ad7f6dd18e975d69bae

Contents?: true

Size: 417 Bytes

Versions: 2

Compression:

Stored size: 417 Bytes

Contents

module Decoradar
  class Collection < Attribute
    attr_reader :serializer

    def initialize(options = {})
      super(options)
      @serializer = options.fetch(:serializer)
    end

    def serialize(hash, collection)
      hash.merge(as => _serialize(collection))
    end

    private

    def _serialize(collection)
      collection.map do |obj|
        serializer.new(obj).as_json
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
decoradar-0.1.1 lib/decoradar/collection.rb
decoradar-0.1.0 lib/decoradar/collection.rb