Sha256: 1a9d5505f487d84faf03684d8cb34e45911c9acd92c4413578fb42c6fc179f00

Contents?: true

Size: 689 Bytes

Versions: 2

Compression:

Stored size: 689 Bytes

Contents

module ActiveRecord
  class Relation
    attr_accessor :standby_target

    # Supports queries like User.on_standby.to_a
    alias_method :exec_queries_without_standby, :exec_queries

    def exec_queries
      if standby_target
        Standby.on_standby(standby_target) { exec_queries_without_standby }
      else
        exec_queries_without_standby
      end
    end


    # Supports queries like User.on_standby.count
    alias_method :calculate_without_standby, :calculate

    def calculate(*args)
      if standby_target
        Standby.on_standby(standby_target) { calculate_without_standby(*args) }
      else
        calculate_without_standby(*args)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
slavery-4.0.0 lib/standby/active_record/relation.rb
standby-4.0.0 lib/standby/active_record/relation.rb