Sha256: 1e37eb04066a5a6868c01f3a4dd34cea8455fcce57815f616eea3bc6df0de0d3

Contents?: true

Size: 1.47 KB

Versions: 1

Compression:

Stored size: 1.47 KB

Contents

module DataMapper
  module Mongo
    module Modifier
      # TODO: document
      # @api public
      def increment(property, value)
        attribute_set(property, attribute_get(property) + value)

        if modifier(:inc, property => value)
          original_attributes.clear
        end
      end

      # TODO: document
      # @api public
      def decrement(property, value)
        attribute_set(property, attribute_get(property) - value)

        if modifier(:inc, property => -value.abs)
          original_attributes.clear
        end
      end

      # TODO: document
      # @api public
      def set(args)
        modifier(:set, args)

        args.keys.each do |key|
          attribute_set(key, args[key])
        end
      end

      # TODO: document
      # @api public
      def unset(*args)
        new_args = {}

        args.each do |arg|
          new_args[arg] = 1
        end

        modifier(:unset, new_args)
      end

      # TODO: document
      # @api public
      def push

      end

      # TODO: document
      # @api public
      def push_all

      end

      # TODO: document
      # @api public
      def pop

      end

      # TODO: document
      # @api public
      def pull

      end

      # TODO: document
      # @api public
      def pull_all

      end

      private

      # TODO: document
      # @api private
      def modifier(operation, properties)
        repository.adapter.execute([self], "$#{operation}" => properties)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dm-mongo-adapter-0.6.0 lib/mongo_adapter/modifier.rb