genghis 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/README.rdoc +3 -8
  2. data/lib/genghis.rb +15 -45
  3. metadata +3 -3
@@ -32,22 +32,17 @@ If you are using replica pairs, the configuration varies somewhat.
32
32
 
33
33
  development:
34
34
  servers:
35
- left: left_host:27017
36
- right: right_host:27017
35
+ -_host:27017
36
+ - right_host:27017
37
37
  databases:
38
38
  paperclip : 'paperclip_files'
39
39
  ...
40
- authorization:
41
- paperclip:
42
- username: pc
43
- password: secretpassword
44
- ...
45
40
  connection_options:
46
41
  max_retries: 7
47
42
  pool_size: 5
48
43
  ...
49
44
 
50
- The left and right servers are specified in a hash, and most importantly for resilience the max_retries
45
+ The servers are specified in an array, and most importantly for resilience the max_retries
51
46
  entry is specified in connection options. This specifies how many times Genghis will try to establish
52
47
  a connection to one of the servers if it detects a connection error.
53
48
 
@@ -10,12 +10,9 @@ class Genghis
10
10
 
11
11
  def self.environment=(environment = :development)
12
12
  yaml = YAML.load_file(config_file)
13
- puts "YAML: #{yaml.inspect}"
14
13
  @@config = yaml[environment.to_s]
15
14
  @@config.each do |k, v|
16
-
17
15
  self.class.instance_eval do
18
- v = HashWithConsistentAccess.new(v) if v.is_a?(::Hash)
19
16
  define_method(k.to_sym){v}
20
17
  end
21
18
  end
@@ -26,7 +23,7 @@ class Genghis
26
23
  end
27
24
 
28
25
  def self.database(db_alias)
29
- connection.db(self.databases[db_alias])
26
+ connection.db(self.databases[db_alias.to_s])
30
27
  end
31
28
 
32
29
  def self.reconnect
@@ -65,9 +62,10 @@ class Genghis
65
62
 
66
63
  def self.safe_create_connection
67
64
  opts = connection_options
68
- if self.servers.is_a? Hash
69
- servers = self.servers
70
- servers = [parse_host(servers['left']), parse_host(servers['right'])]
65
+ if self.servers.is_a? Array
66
+ servers = self.servers.collect{|x| parse_host(x)}
67
+ puts "Multi called with #{servers.inspect} #{opts.inspect}"
68
+
71
69
  connection = Connection.multi(servers, opts)
72
70
  else
73
71
  host, port = parse_host(self.servers)
@@ -79,11 +77,11 @@ class Genghis
79
77
  def self.parse_host(host)
80
78
  a = host.split(':')
81
79
  a << 27017 if a.size == 1
82
- a
80
+ [a.first, a.last.to_i]
83
81
  end
84
82
 
85
83
  def self.symbolize_keys(hash)
86
- hash.inject({}) { |memo, (k, v)| memo[k.to_sym] = v; memo }
84
+ hash.inject({}){|memo, (k, v)| memo[k.to_sym] = v; memo}
87
85
  end
88
86
 
89
87
 
@@ -107,9 +105,9 @@ class Genghis
107
105
  @@protected_classes.include? clazz
108
106
  end
109
107
 
110
- def method_missing(method, * args, & block)
108
+ def method_missing(method, *args, &block)
111
109
  protect_from_exception do
112
- Guardian.make_safe(@protected_class.__send__(method, * args, & block))
110
+ Guardian.make_safe(@protected_class.__send__(method, *args, &block))
113
111
  end
114
112
  end
115
113
 
@@ -121,7 +119,7 @@ class Genghis
121
119
  true
122
120
  end
123
121
 
124
- def protect_from_exception(& block)
122
+ def protect_from_exception(&block)
125
123
  success = false
126
124
  max_retries = Genghis.max_retries
127
125
  retries = 0
@@ -150,41 +148,14 @@ class Genghis
150
148
  end
151
149
  end
152
150
 
153
- class HashWithConsistentAccess
154
-
155
- def initialize(proxied={})
156
- @proxied = proxied.inject({}) do |memo, (k, v)|
157
- memo[k.to_s] = v
158
- memo
159
- end
160
- end
161
-
162
-
163
- def []=(key, value)
164
- @proxied[key.to_s] = value
165
- end
166
-
167
- def [](key)
168
- @proxied[key.to_s]
169
- end
170
-
171
- def key?(key)
172
- @proxied.key?(key.to_s)
173
- end
174
-
175
- def inspect
176
- @proxied.inspect
177
- end
178
- end
179
-
180
151
 
181
152
  class Guardian
182
153
  alias_method :old_class, :class
183
- instance_methods.each { |m| undef_method m unless m =~ /^__|^old/ }
154
+ instance_methods.each { |m| undef_method m unless m =~ /^__|^old/}
184
155
 
185
156
  include ProxyMethods
186
157
 
187
- def initialize(* args)
158
+ def initialize(*args)
188
159
 
189
160
  opts = args.extract_options!
190
161
  if opts.empty?
@@ -225,10 +196,10 @@ class Genghis
225
196
  end
226
197
 
227
198
 
228
- def method_missing(method, * args, & block)
199
+ def method_missing(method, *args, &block)
229
200
  return true if method == :safe?
230
201
  self.old_class.protect_from_exception do
231
- Guardian.make_safe(@protected.__send__(method, * args, & block))
202
+ Guardian.make_safe(@protected.__send__(method, *args, &block))
232
203
  end
233
204
  end
234
205
 
@@ -242,5 +213,4 @@ class Genghis
242
213
  end
243
214
  end
244
215
 
245
-
246
- end
216
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: genghis
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 3
10
- version: 1.0.3
9
+ - 4
10
+ version: 1.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Steve Cohen