Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Taken from http://pastebin.com/xWU62iT2
- # See https://github.com/datamapper/dm-types/issues/44
- # with modifications for sql server
- module DataMapper
- class Query
- module Conditions
- # Tests whether the value in the record
- # has the specified bits set to true (bitwise and)
- class HasComparison < AbstractComparison
- slug :has
- def matches?(record)
- record_value = record_value(record)
- !record_value.nil? && (record_value & expected)
- end
- # @return [String]
- #
- # @see AbstractComparison#to_s
- #
- # @api private
- def comparator_string
- '&'
- end
- end # class HasFlagComparison
- end # module Conditions
- end # class Query
- end # module DataMapper
- module DataMapper
- module Adapters
- class DataObjectsAdapter < AbstractAdapter
- def comparison_operator(comparison)
- subject = comparison.subject
- value = comparison.value
- case comparison.slug
- when :has then has_operator(subject, value)
- when :eql then equality_operator(subject, value)
- when :in then include_operator(subject, value)
- when :regexp then regexp_operator(value)
- when :like then like_operator(value)
- when :gt then '>'
- when :lt then '<'
- when :gte then '>='
- when :lte then '<='
- end
- end
- def has_operator(property, operand)
- "& #{operand} ="
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement