Sha256: a799ceaa9e124990c80fdd3e2fabb41ef214505b32742270a73f7b2ef359fd8b

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

module Searchlogic
  module Conditions
    # = Any or All
    #
    # Adds the ability to join all conditions wth "ANY" or "ALL".
    module AnyOrAll
      # Determines if we should join the conditions with "AND" or "OR".
      #
      # === Examples
      #
      #   search.conditions.any = true # will join all conditions with "or", you can also set this to "true", "1", or "yes"
      #   search.conditions.any = false # will join all conditions with "and"
      def any=(value)
        objects.each { |object| object.any = value }
        @any = value
      end
      
      def any # :nodoc:
        any?
      end
      
      # Convenience method for determining if we should join the conditions with "AND" or "OR".
      def any?
        ["true", "1", "yes"].include? @any.to_s
      end
      
      # Sets the conditions to be searched by "or"
      def any!
        self.any = true
      end
      
      def all? # :nodoc:
        !any?
      end
      
      # Sets the conditions to be searched by "and"
      def all!
        self.any = false
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
searchlogic-1.5.6 lib/searchlogic/conditions/any_or_all.rb