Sha256: e9dd64ff8f98cfc3166602ea94b518142c819f7da1c089194b5507da458d8301

Contents?: true

Size: 759 Bytes

Versions: 1

Compression:

Stored size: 759 Bytes

Contents

require 'mayu/stores/base'

module Mayu
  module Stores
    class Concat < Base
      def initialize(stores:)
        @stores = stores
      end

      attr_reader :stores

      def put(obj)
        raise NotImplementedError, "this store is read only"
      end

      def get
        objs = @stores.map(&:get)
        keys = objs.flat_map(&:keys).uniq

        r = {}
        objs.each do |i|
          keys.each do |k|
            next unless i[k]
            case r[k]
            when Array
              r[k] ||= []
              r[k] += i[k]
            when Hash
              r[k] ||= {}
              r[k] = r[k].merge(i[k])
            else
              r[k] = i[k]
            end
          end
        end
        r
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mayu-0.1.0.beta1 lib/mayu/stores/concat.rb