Sha256: 4f0c92a52a00d36e6da206dd9da8b24ca23fa399aafa0dbb25b37d32faca2468

Contents?: true

Size: 1.08 KB

Versions: 14

Compression:

Stored size: 1.08 KB

Contents

# encoding: utf-8
module Mongoid
  module Persistable

    # Defines behaviour for logical bitwise operations.
    #
    # @since 4.0.0
    module Logical
      extend ActiveSupport::Concern

      # Performs an atomic $bit operation on the field with the provided hash
      # of bitwise ops to execute in order.
      #
      # @example Execute the bitwise operations.
      #   person.bit(age: { :and => 12 }, val: { and: 10, or: 12 })
      #
      # @param [ Hash ] operations The bitwise operations.
      #
      # @return [ true, false ] If the operation succeeded.
      #
      # @since 4.0.0
      def bit(operations)
        prepare_atomic_operation do |ops|
          process_atomic_operations(operations) do |field, values|
            value = attributes[field]
            values.each do |op, val|
              value = value & val if op.to_s == "and"
              value = value | val if op.to_s == "or"
            end
            attributes[field] = value
            ops[atomic_attribute_name(field)] = values
          end
          { "$bit" => ops }
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 5 rubygems

Version Path
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/mongoid-4.0.2/lib/mongoid/persistable/logical.rb
mongoid-4.0.2 lib/mongoid/persistable/logical.rb
mongoid-4.0.1 lib/mongoid/persistable/logical.rb
mongoid-4.0.0 lib/mongoid/persistable/logical.rb
mongoid-4.0.0.rc2 lib/mongoid/persistable/logical.rb
mongoid-4.0.0.rc1 lib/mongoid/persistable/logical.rb
mongoid-4.0.0.beta2 lib/mongoid/persistable/logical.rb
mongoid-4.0.0.beta1 lib/mongoid/persistable/logical.rb
mongoid-4.0.0.alpha2 lib/mongoid/persistable/logical.rb
mongoid-4.0.0.alpha1 lib/mongoid/persistable/logical.rb
sepastian-mongoid-rails4-4.0.1.alpha lib/mongoid/persistable/logical.rb
sepastian-mongoid-rails4-4.0.0.alpha lib/mongoid/persistable/logical.rb
mongoid_heroku_stable-4.0.0 lib/mongoid/persistable/logical.rb
mongoid_rails4-4.0.0 lib/mongoid/persistable/logical.rb