Sha256: cd1079f634c7f0e946157acb17add11b39b8741f5548e5d64373ab5c4ec44e6e

Contents?: true

Size: 699 Bytes

Versions: 2

Compression:

Stored size: 699 Bytes

Contents

# frozen_string_literal: true

module ActiveRecordBitmask
  module AttributeMethods
    module Query
      private

      def bitmask_attribute?(attribute_name)
        self.class.bitmasks.key?(attribute_name.to_sym)
      end

      def attribute?(attribute_name, *values)
        if bitmask_attribute?(attribute_name) && values.present?
          # assert bitmask values
          map = self.class.bitmask_for(attribute_name)
          expected_value = map.attributes_to_bitmask(values)
          current_value = map.attributes_to_bitmask(attribute(attribute_name))

          (current_value & expected_value) == expected_value
        else
          super
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
active_record_bitmask-0.0.5 lib/active_record_bitmask/attribute_methods/query.rb
active_record_bitmask-0.0.4 lib/active_record_bitmask/attribute_methods/query.rb