Module: Standby

Defined in:
lib/standby.rb,
lib/standby/base.rb,
lib/standby/error.rb,
lib/standby/version.rb,
lib/standby/transaction.rb,
lib/standby/connection_holder.rb

Defined Under Namespace

Classes: Base, ConnectionHolder, Error, Transaction

Constant Summary collapse

VERSION =
'5.1.0'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.disabledObject

Returns the value of attribute disabled.



18
19
20
# File 'lib/standby.rb', line 18

def disabled
  @disabled
end

Class Method Details

.connection_holder(target) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/standby/connection_holder.rb', line 23

def connection_holder(target)
  klass_name = "Standby#{target.to_s.camelize}ConnectionHolder"
  standby_connections[klass_name] || standby_connections_mutex.synchronize do
    standby_connections[klass_name] ||= begin
      klass = Class.new(Standby::ConnectionHolder) do
        self.abstract_class = true
      end
      Object.const_set(klass_name, klass)
      klass.activate(target)
      klass
    end
  end
end

.on_primary(&block) ⇒ Object



33
34
35
# File 'lib/standby.rb', line 33

def on_primary(&block)
  Base.new(:primary).run &block
end

.on_standby(name = :null_state, &block) ⇒ Object

Raises:



28
29
30
31
# File 'lib/standby.rb', line 28

def on_standby(name = :null_state, &block)
  raise Standby::Error.new('invalid standby target') unless name.is_a?(Symbol)
  Base.new(name).run &block
end

.standby_connectionsObject



20
21
22
# File 'lib/standby.rb', line 20

def standby_connections
  @standby_connections
end

.standby_connections_mutexObject



24
25
26
# File 'lib/standby.rb', line 24

def standby_connections_mutex
  @standby_connections_mutex
end

.version_gte?(version) ⇒ Boolean

Returns:

  • (Boolean)


5
6
7
# File 'lib/standby/version.rb', line 5

def version_gte?(version)
  Gem::Version.new(ActiveRecord.version) >= Gem::Version.new(version)
end