Sha256: db9046f55651c8da43b8928865bc3c259cee2eaf48b26ba2c5362dd370f855df

Contents?: true

Size: 696 Bytes

Versions: 1

Compression:

Stored size: 696 Bytes

Contents

class ActiveRecord::Relation
  attr_accessor :slavery_target

  # Supports queries like User.on_slave.all
  def exec_queries_with_slavery
    if slavery_target == :slave
      Slavery.on_slave { exec_queries_without_slavery }
    else
      exec_queries_without_slavery
    end
  end

  # Supports queries like User.on_slave.count
  def calculate_with_slavery(operation, column_name, options = {})
    if slavery_target == :slave
      Slavery.on_slave { calculate_without_slavery(operation, column_name, options) }
    else
      calculate_without_slavery(operation, column_name, options)
    end
  end

  alias_method_chain :exec_queries, :slavery
  alias_method_chain :calculate, :slavery
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
slavery-1.2.0 lib/slavery/relation.rb