Module: Switchman::ActiveRecord::StatementCache::ClassMethods

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

Instance Method Summary collapse

Instance Method Details

#create(connection, block = Proc.new) ⇒ Object



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

def create(connection, block = Proc.new)
  relation = block.call ::ActiveRecord::StatementCache::Params.new

  if ::Rails.version >= "5.2"
    query_builder, binds = connection.cacheable_query(self, relation.arel)
    bind_map = ::ActiveRecord::StatementCache::BindMap.new(binds)
    new(relation.arel, bind_map, relation.klass)
  else
    bind_map = ::ActiveRecord::StatementCache::BindMap.new(relation.bound_attributes)
    new relation.arel, bind_map
  end
end