Module: FreshConnection::Extend::ArBase

Defined in:
lib/fresh_connection/extend/ar_base.rb

Instance Method Summary collapse

Instance Method Details

#clear_all_replica_connections!Object



42
43
44
# File 'lib/fresh_connection/extend/ar_base.rb', line 42

def clear_all_replica_connections!
  replica_connection_handler.clear_all_connections!
end

#clear_all_slave_connections!Object



46
47
48
49
50
51
52
# File 'lib/fresh_connection/extend/ar_base.rb', line 46

def clear_all_slave_connections!
  ActiveSupport::Deprecation.warn(
    "'clear_all_slave_connections!' is deprecated and will removed from version 2.4.0. use 'clear_all_replica_connections!' instead."
  )

  clear_all_replica_connections!
end

#connectionObject



8
9
10
11
12
13
14
15
16
# File 'lib/fresh_connection/extend/ar_base.rb', line 8

def connection
  master_c = super
  return master_c unless FreshConnection::AccessControl.replica_access?

  replica_c = replica_connection
  replica_c.master_connection = master_c
  replica_c.replica_group = replica_group if logger && logger.debug?
  replica_c
end

#establish_fresh_connection(replica_group = "replica") ⇒ Object



26
27
28
# File 'lib/fresh_connection/extend/ar_base.rb', line 26

def establish_fresh_connection(replica_group = "replica")
  replica_connection_handler.establish_connection(name, replica_group)
end

#master_db_only!Object



54
55
56
# File 'lib/fresh_connection/extend/ar_base.rb', line 54

def master_db_only!
  @_fresh_connection_master_only = true
end

#master_db_only?Boolean

Returns:

  • (Boolean)


58
59
60
61
# File 'lib/fresh_connection/extend/ar_base.rb', line 58

def master_db_only?
  @_fresh_connection_master_only ||=
    (self != ActiveRecord::Base && superclass.master_db_only?)
end

#read_masterObject



18
19
20
# File 'lib/fresh_connection/extend/ar_base.rb', line 18

def read_master
  all.read_master
end

#replica_connectionObject



30
31
32
# File 'lib/fresh_connection/extend/ar_base.rb', line 30

def replica_connection
  replica_connection_handler.connection(self)
end

#replica_connection_put_aside!Object



63
64
65
# File 'lib/fresh_connection/extend/ar_base.rb', line 63

def replica_connection_put_aside!
  replica_connection_handler.put_aside!
end

#replica_connection_recovery?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/fresh_connection/extend/ar_base.rb', line 75

def replica_connection_recovery?
  replica_connection_handler.recovery?(self)
end

#replica_groupObject



87
88
89
# File 'lib/fresh_connection/extend/ar_base.rb', line 87

def replica_group
  replica_connection_handler.replica_group(self)
end

#slave_connectionObject



34
35
36
37
38
39
40
# File 'lib/fresh_connection/extend/ar_base.rb', line 34

def slave_connection
  ActiveSupport::Deprecation.warn(
    "'slave_connection' is deprecated and will removed from version 2.4.0. use 'replica_connection' instead."
  )

  replica_connection
end

#slave_connection_put_aside!Object



67
68
69
70
71
72
73
# File 'lib/fresh_connection/extend/ar_base.rb', line 67

def slave_connection_put_aside!
  ActiveSupport::Deprecation.warn(
    "'slave_connection_put_aside!' is deprecated and will removed from version 2.4.0. use 'replica_connection_put_aside!' instead."
  )

  replica_connection_put_aside!
end

#slave_connection_recovery?Boolean

Returns:

  • (Boolean)


79
80
81
82
83
84
85
# File 'lib/fresh_connection/extend/ar_base.rb', line 79

def slave_connection_recovery?
  ActiveSupport::Deprecation.warn(
    "'slave_connection_recovery?' is deprecated and will removed from version 2.4.0. use 'replica_connection_recovery?' instead."
  )

  replica_connection_recovery?
end

#slave_groupObject



91
92
93
94
95
96
97
# File 'lib/fresh_connection/extend/ar_base.rb', line 91

def slave_group
  ActiveSupport::Deprecation.warn(
    "'slave_connection_recovery?' is deprecated and will removed from version 2.4.0. use 'replica_connection_recovery?' instead."
  )

  replica_group
end

#with_master(&block) ⇒ Object



22
23
24
# File 'lib/fresh_connection/extend/ar_base.rb', line 22

def with_master(&block)
  all.manage_access(false, &block)
end