Sha256: 5ff2e13ff880228e43be5b0f48c89d10116ddfeca9f21df3e52d23172c5a465a

Contents?: true

Size: 1.42 KB

Versions: 9

Compression:

Stored size: 1.42 KB

Contents

module Searchgasm
  module Shared
    module Utilities # :nodoc:
      private
        def merge_conditions(*conditions)
          options = conditions.extract_options!
          conditions.delete_if { |condition| condition.blank? }
          return if conditions.blank?
          return conditions.first if conditions.size == 1
        
          conditions_strs = []
          conditions_subs = []
        
          conditions.each do |condition|
            next if condition.blank?
            arr_condition = condition.is_a?(Array) ? condition : [condition]
            conditions_strs << arr_condition.first
            conditions_subs += arr_condition[1..-1]
          end
        
          return if conditions_strs.blank?
        
          join = options[:any] ? "OR" : "AND"
          conditions_str = "(#{conditions_strs.join(") #{join} (")})"
        
          return conditions_str if conditions_subs.blank?
        
          [conditions_str, *conditions_subs]
        end
        
        def merge_joins(*joins)
          joins.delete_if { |join| join.blank? }
          return if joins.blank?
          return joins.first if joins.size == 1
          
          new_joins = []
          joins.each do |join|
            case join
            when Array
              new_joins += join
            else
              new_joins << join
            end
          end
          
          new_joins.compact.uniq
        end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
searchgasm-1.3.4 lib/searchgasm/shared/utilities.rb
searchgasm-1.3.3 lib/searchgasm/shared/utilities.rb
searchgasm-1.5.1 lib/searchgasm/shared/utilities.rb
searchgasm-1.5.0 lib/searchgasm/shared/utilities.rb
searchgasm-1.5.2 lib/searchgasm/shared/utilities.rb
searchgasm-1.4.0 lib/searchgasm/shared/utilities.rb
searchgasm-1.4.1 lib/searchgasm/shared/utilities.rb
searchgasm-1.5.3 lib/searchgasm/shared/utilities.rb
searchgasm-1.3.5 lib/searchgasm/shared/utilities.rb