Module: Switchman::ActiveRecord::WhereClauseFactory

Defined in:
lib/switchman/active_record/where_clause_factory.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#scope=(value) ⇒ Object (writeonly)

Sets the attribute scope

Parameters:

  • value

    the value to set the attribute scope to.



4
5
6
# File 'lib/switchman/active_record/where_clause_factory.rb', line 4

def scope=(value)
  @scope = value
end

Instance Method Details

#build(opts, other = []) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/switchman/active_record/where_clause_factory.rb', line 6

def build(opts, other = [])
  case opts
    when Hash, ::Arel::Nodes::Node
      where_clause = super
      predicates = where_clause.send(:predicates)
      @scope.send(:infer_shards_from_primary_key, predicates, where_clause.binds) if @scope.shard_source_value == :implicit && @scope.shard_value.is_a?(Shard)
      predicates = @scope.transpose_predicates(predicates, nil, @scope.primary_shard, false, where_clause.binds) if @scope.shard_source_value != :explicit
      where_clause.instance_variable_set(:@predicates, predicates)
      where_clause
    else
      super
  end
end