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 =
'4.0.0'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.disabledObject

Returns the value of attribute disabled.



14
15
16
# File 'lib/standby.rb', line 14

def disabled
  @disabled
end

Class Method Details

.connection_holder(target) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/standby/connection_holder.rb', line 16

def connection_holder(target)
  klass_name = "Standby#{target.to_s.camelize}ConnectionHolder"
  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

.on_primary(&block) ⇒ Object



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

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

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

Raises:



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

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



16
17
18
# File 'lib/standby.rb', line 16

def standby_connections
  @standby_connections ||= {}
end