Class: BigRails::Redis::Registry
- Inherits:
-
Object
- Object
- BigRails::Redis::Registry
show all
- Defined in:
- lib/big_rails/redis/registry.rb
Defined Under Namespace
Classes: UnknownConnection, VerificationError
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of Registry.
14
15
16
17
18
|
# File 'lib/big_rails/redis/registry.rb', line 14
def initialize
@connections = {}
@wrapped_connections = {}
@builder = Builder
end
|
Instance Attribute Details
#builder ⇒ Object
Returns the value of attribute builder.
12
13
14
|
# File 'lib/big_rails/redis/registry.rb', line 12
def builder
@builder
end
|
Instance Method Details
#config_for(name) ⇒ Object
30
31
32
|
# File 'lib/big_rails/redis/registry.rb', line 30
def config_for(name)
configurations[validate_name(name)].deep_dup
end
|
#disconnect ⇒ Object
38
39
40
41
42
43
44
45
46
|
# File 'lib/big_rails/redis/registry.rb', line 38
def disconnect
each do |connection|
if connection.is_a?(::ConnectionPool)
connection.reload { |conn| conn.close }
else
connection.close
end
end
end
|
#each(&block) ⇒ Object
34
35
36
|
# File 'lib/big_rails/redis/registry.rb', line 34
def each(&block)
configurations.keys.map { |name| self.for(name) }.each(&block)
end
|
#for(name, wrapped: false) ⇒ Object
20
21
22
23
24
25
26
27
28
|
# File 'lib/big_rails/redis/registry.rb', line 20
def for(name, wrapped: false)
name = validate_name(name)
if wrapped
@wrapped_connections[name] ||= build_wrapped_connection(self.for(name))
else
@connections[name] ||= build_connection(name)
end
end
|
#verify!(*names) ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/big_rails/redis/registry.rb', line 48
def verify!(*names)
names.map! { |name| validate_name(name) }
names = configurations.keys if names.empty?
names.each do |name|
self.for(name).with do |connection|
next if connection.connected?
begin
connection.quit
rescue
raise VerificationError, "verification for '#{name}' failed"
end
end
end
true
end
|