Sha256: cd61213ce56a8e166cf1af3a41c607965f56c8a414d40732e8e9853ba499b99d

Contents?: true

Size: 957 Bytes

Versions: 12

Compression:

Stored size: 957 Bytes

Contents

# -*- encoding : utf-8 -*-
module SecondLevelCache
  module Arel
    class Wheres
      attr_reader :where_values

      def initialize(where_values)
        @where_values = where_values
      end

      # Determine whether all conditions is equality, for example:
      #
      #     Article.where("user_id = 1").where(:status => 1).find(1)
      def all_equality?
        where_values.all?{|where_value| where_value.is_a?(::Arel::Nodes::Equality)}
      end

      # Extract conditions to pairs, for checking whether cache match the conditions.
      def extract_pairs
        where_values.map do |where_value|
          if where_value.is_a?(String)
            left, right = where_value.split(/\s*=\s*/, 2)
            right = right.to_i
          else
            left, right = where_value.left.name, where_value.right
          end
          {
            :left  => left,
            :right => right
          }
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
second_level_cache-2.1.0 lib/second_level_cache/arel/wheres.rb
second_level_cache-2.1.0.rc2 lib/second_level_cache/arel/wheres.rb
second_level_cache-2.1.0.rc1 lib/second_level_cache/arel/wheres.rb
second_level_cache-2.0.0 lib/second_level_cache/arel/wheres.rb
second_level_cache-2.0.0.rc1 lib/second_level_cache/arel/wheres.rb
second_level_cache-2.0.0.beta lib/second_level_cache/arel/wheres.rb
second_level_cache-1.6.2 lib/second_level_cache/arel/wheres.rb
second_level_cache-1.6.1 lib/second_level_cache/arel/wheres.rb
second_level_cache-1.6.0 lib/second_level_cache/arel/wheres.rb
second_level_cache-1.5.1 lib/second_level_cache/arel/wheres.rb
second_level_cache-1.5.0 lib/second_level_cache/arel/wheres.rb
second_level_cache-1.3.2 lib/second_level_cache/arel/wheres.rb