Sha256: 2569ef6208a18afcc020f5cf28f3b217d90ef9c45a37e2df4fc9681f59f5a9d0

Contents?: true

Size: 1.25 KB

Versions: 22

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true

module Switchman
  module ActiveRecord
    module WhereClauseFactory
      attr_writer :scope

      def build(opts, other = [])
        case opts
        when String, Array
          values = Hash === other.first ? other.first.values : other

          values.grep(ActiveRecord::Relation) do |rel|
            # serialize subqueries against the same shard as the outer query is currently
            # targeted to run against
            if rel.shard_source_value == :implicit && rel.primary_shard != @scope.primary_shard
              rel.shard!(@scope.primary_shard)
            end
          end

          super
        when Hash, ::Arel::Nodes::Node
          where_clause = super
          binds = ::Rails.version >= "5.2" ? nil : where_clause.binds
          predicates = where_clause.send(:predicates)
          @scope.send(:infer_shards_from_primary_key, predicates, binds) if @scope.shard_source_value == :implicit && @scope.shard_value.is_a?(Shard)
          predicates, _new_binds = @scope.transpose_predicates(predicates, nil, @scope.primary_shard, false, binds: binds)
          where_clause.instance_variable_set(:@predicates, predicates)
          where_clause
        else
          super
        end
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
switchman-2.2.3 lib/switchman/active_record/where_clause_factory.rb
switchman-2.2.2 lib/switchman/active_record/where_clause_factory.rb
switchman-2.2.1 lib/switchman/active_record/where_clause_factory.rb
switchman-2.2.0 lib/switchman/active_record/where_clause_factory.rb
switchman-2.1.6 lib/switchman/active_record/where_clause_factory.rb
switchman-2.1.5 lib/switchman/active_record/where_clause_factory.rb
switchman-2.1.4 lib/switchman/active_record/where_clause_factory.rb
switchman-2.1.3 lib/switchman/active_record/where_clause_factory.rb
switchman-2.1.2 lib/switchman/active_record/where_clause_factory.rb
switchman-2.1.1 lib/switchman/active_record/where_clause_factory.rb
switchman-2.1.0 lib/switchman/active_record/where_clause_factory.rb
switchman-2.0.13 lib/switchman/active_record/where_clause_factory.rb
switchman-2.0.12 lib/switchman/active_record/where_clause_factory.rb
switchman-2.0.11 lib/switchman/active_record/where_clause_factory.rb
switchman-2.0.10 lib/switchman/active_record/where_clause_factory.rb
switchman-2.0.9 lib/switchman/active_record/where_clause_factory.rb
switchman-2.0.8 lib/switchman/active_record/where_clause_factory.rb
switchman-2.0.7 lib/switchman/active_record/where_clause_factory.rb
switchman-2.0.6 lib/switchman/active_record/where_clause_factory.rb
switchman-2.0.5 lib/switchman/active_record/where_clause_factory.rb