Sha256: 13e0c2ec95eb441cbed44b6bc37cf5f55add599bd362f3d5a98e429594ada882

Contents?: true

Size: 1.78 KB

Versions: 12

Compression:

Stored size: 1.78 KB

Contents

module Riak
  module Crdt
    # A map that exists inside a {TypedCollection} inside another map.
    class InnerMap
      attr_reader :counters, :flags, :maps, :registers, :sets

      attr_accessor :name

      # The parent of this counter.
      #
      # @api private
      attr_reader :parent

      # @api private
      def initialize(parent, value = {})
        @parent = parent
        @value = value.symbolize_keys

        initialize_collections
      end

      # @api private
      def operate(inner_operation)
        wrapped_operation = Operation::Update.new.tap do |op|
          op.value = inner_operation
          op.type = :map
        end

        @parent.operate(name, wrapped_operation)
      end

      def pretty_print(pp)
        pp.object_group self do
          %w{counters flags maps registers sets}.each do |h|
            pp.comma_breakable
            pp.text "#{h}="
            pp.pp send h
          end
        end
      end

      def pretty_print_cycle(pp)
        pp.text "InnerMap"
      end

      def to_value_h
        %w{counters flags maps registers sets}.map do |k|
          [k, send(k).to_value_h]
        end.to_h
      end

      alias :value :to_value_h

      # @api private
      def self.delete
        Operation::Delete.new.tap do |op|
          op.type = :map
        end
      end

      def context?
        @parent.context?
      end

      private
      def initialize_collections
        @counters = TypedCollection.new InnerCounter, self, @value[:counters]
        @flags = TypedCollection.new InnerFlag, self, @value[:flags]
        @maps = TypedCollection.new InnerMap, self, @value[:maps]
        @registers = TypedCollection.new InnerRegister, self, @value[:registers]
        @sets = TypedCollection.new InnerSet, self, @value[:sets]
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
riak-client-2.6.0 lib/riak/crdt/inner_map.rb
riak-client-2.5.0 lib/riak/crdt/inner_map.rb
riak-client-2.4.1 lib/riak/crdt/inner_map.rb
riak-client-2.4.0 lib/riak/crdt/inner_map.rb
riak-client-2.4.0.pre1 lib/riak/crdt/inner_map.rb
riak-client-2.3.2 lib/riak/crdt/inner_map.rb
riak-client-2.3.1 lib/riak/crdt/inner_map.rb
riak-client-2.3.0 lib/riak/crdt/inner_map.rb
riak-client-2.2.2 lib/riak/crdt/inner_map.rb
riak-client-2.2.1 lib/riak/crdt/inner_map.rb
riak-client-noenc-1.0.0 lib/riak/crdt/inner_map.rb
riak-client-2.2.0 lib/riak/crdt/inner_map.rb