Class: Genghis
- Inherits:
-
Object
show all
- Includes:
- Mongo
- Defined in:
- lib/genghis.rb
Defined Under Namespace
Modules: ProxyMethods
Classes: ArrayProxy, Guardian, HashWithConsistentAccess
Class Method Summary
collapse
Class Method Details
.config=(path) ⇒ Object
16
17
18
|
# File 'lib/genghis.rb', line 16
def self.config=(path)
@@config_file = path
end
|
.connection ⇒ Object
52
53
54
|
# File 'lib/genghis.rb', line 52
def self.connection
@connection ||= safe_create_connection
end
|
.database(db_alias) ⇒ Object
56
57
58
|
# File 'lib/genghis.rb', line 56
def self.database(db_alias)
connection.db(self.databases[db_alias.to_s])
end
|
.environment=(environment = :development) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/genghis.rb', line 20
def self.environment=(environment = :development)
yaml = YAML.load_file(config_file)
@connection = nil
@@config = yaml[environment.to_s]
@@config.each do |k, v|
if k == 'server'
self.hosts = parse_mongo_urls([v])
elsif k == 'replica_set'
self.hosts = parse_mongo_urls(v)
elsif k == 'resilience_options'
v.each_pair do |opt, setting|
self.send("#{opt}=".to_sym, setting)
end
else
self.class.instance_eval do
v = HashWithConsistentAccess.new(v) if v.is_a?(::Hash)
define_method(k.to_sym) { v }
end
end
end
parse_connection_options unless @@config['connection_options'].nil?
nil
end
|
.failure_callback ⇒ Object
48
49
50
|
# File 'lib/genghis.rb', line 48
def self.failure_callback
@failure_method
end
|
.hosts ⇒ Object
8
9
10
|
# File 'lib/genghis.rb', line 8
def self.hosts
@@hosts
end
|
.hosts=(host_list) ⇒ Object
12
13
14
|
# File 'lib/genghis.rb', line 12
def self.hosts=(host_list)
@@hosts = host_list
end
|
.max_retries ⇒ Object
68
69
70
|
# File 'lib/genghis.rb', line 68
def self.max_retries
@@retries ||= 5
end
|
.max_retries=(num) ⇒ Object
64
65
66
|
# File 'lib/genghis.rb', line 64
def self.max_retries=(num)
@@retries = num
end
|
.on_failure(&block) ⇒ Object
44
45
46
|
# File 'lib/genghis.rb', line 44
def self.on_failure(&block)
@failure_method = block if block_given?
end
|
.reconnect ⇒ Object
60
61
62
|
# File 'lib/genghis.rb', line 60
def self.reconnect
@connection = safe_create_connection
end
|
.sleep_between_retries ⇒ Object
76
77
78
|
# File 'lib/genghis.rb', line 76
def self.sleep_between_retries
@@sleep_time || 1
end
|
.sleep_between_retries=(num) ⇒ Object
72
73
74
|
# File 'lib/genghis.rb', line 72
def self.sleep_between_retries=(num)
@@sleep_time = num
end
|