genghis 1.0.2 → 1.0.3

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 +5 -0
  2. data/lib/genghis.rb +41 -11
  3. metadata +11 -4
@@ -37,6 +37,11 @@ If you are using replica pairs, the configuration varies somewhat.
37
37
  databases:
38
38
  paperclip : 'paperclip_files'
39
39
  ...
40
+ authorization:
41
+ paperclip:
42
+ username: pc
43
+ password: secretpassword
44
+ ...
40
45
  connection_options:
41
46
  max_retries: 7
42
47
  pool_size: 5
@@ -5,15 +5,17 @@ class Genghis
5
5
  include Mongo
6
6
 
7
7
  def self.config=(path)
8
- puts "Setting config to #{path}"
9
8
  @@config_file = path
10
9
  end
11
10
 
12
11
  def self.environment=(environment = :development)
13
12
  yaml = YAML.load_file(config_file)
13
+ puts "YAML: #{yaml.inspect}"
14
14
  @@config = yaml[environment.to_s]
15
15
  @@config.each do |k, v|
16
+
16
17
  self.class.instance_eval do
18
+ v = HashWithConsistentAccess.new(v) if v.is_a?(::Hash)
17
19
  define_method(k.to_sym){v}
18
20
  end
19
21
  end
@@ -66,7 +68,7 @@ class Genghis
66
68
  if self.servers.is_a? Hash
67
69
  servers = self.servers
68
70
  servers = [parse_host(servers['left']), parse_host(servers['right'])]
69
- connection = Connection.paired(servers, opts)
71
+ connection = Connection.multi(servers, opts)
70
72
  else
71
73
  host, port = parse_host(self.servers)
72
74
  connection = Connection.new(host, port, opts)
@@ -81,7 +83,7 @@ class Genghis
81
83
  end
82
84
 
83
85
  def self.symbolize_keys(hash)
84
- hash.inject({}){|memo, (k, v)| memo[k.to_sym] = v; memo}
86
+ hash.inject({}) { |memo, (k, v)| memo[k.to_sym] = v; memo }
85
87
  end
86
88
 
87
89
 
@@ -105,9 +107,9 @@ class Genghis
105
107
  @@protected_classes.include? clazz
106
108
  end
107
109
 
108
- def method_missing(method, *args, &block)
110
+ def method_missing(method, * args, & block)
109
111
  protect_from_exception do
110
- Guardian.make_safe(@protected_class.__send__(method, *args, &block))
112
+ Guardian.make_safe(@protected_class.__send__(method, * args, & block))
111
113
  end
112
114
  end
113
115
 
@@ -119,7 +121,7 @@ class Genghis
119
121
  true
120
122
  end
121
123
 
122
- def protect_from_exception(&block)
124
+ def protect_from_exception(& block)
123
125
  success = false
124
126
  max_retries = Genghis.max_retries
125
127
  retries = 0
@@ -148,14 +150,41 @@ class Genghis
148
150
  end
149
151
  end
150
152
 
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
+
151
180
 
152
181
  class Guardian
153
182
  alias_method :old_class, :class
154
- instance_methods.each { |m| undef_method m unless m =~ /^__|^old/}
183
+ instance_methods.each { |m| undef_method m unless m =~ /^__|^old/ }
155
184
 
156
185
  include ProxyMethods
157
186
 
158
- def initialize(*args)
187
+ def initialize(* args)
159
188
 
160
189
  opts = args.extract_options!
161
190
  if opts.empty?
@@ -196,10 +225,10 @@ class Genghis
196
225
  end
197
226
 
198
227
 
199
- def method_missing(method, *args, &block)
228
+ def method_missing(method, * args, & block)
200
229
  return true if method == :safe?
201
230
  self.old_class.protect_from_exception do
202
- Guardian.make_safe(@protected.__send__(method, *args, &block))
231
+ Guardian.make_safe(@protected.__send__(method, * args, & block))
203
232
  end
204
233
  end
205
234
 
@@ -213,4 +242,5 @@ class Genghis
213
242
  end
214
243
  end
215
244
 
216
- end
245
+
246
+ end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: genghis
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 17
4
5
  prerelease: false
5
6
  segments:
6
7
  - 1
7
8
  - 0
8
- - 2
9
- version: 1.0.2
9
+ - 3
10
+ version: 1.0.3
10
11
  platform: ruby
11
12
  authors:
12
13
  - Steve Cohen
@@ -14,16 +15,18 @@ autorequire: genghis
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-03-18 00:00:00 -07:00
18
+ date: 2010-08-31 00:00:00 -07:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: mongo
22
23
  prerelease: false
23
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
24
26
  requirements:
25
27
  - - ">="
26
28
  - !ruby/object:Gem::Version
29
+ hash: 45
27
30
  segments:
28
31
  - 0
29
32
  - 19
@@ -51,23 +54,27 @@ rdoc_options: []
51
54
  require_paths:
52
55
  - lib
53
56
  required_ruby_version: !ruby/object:Gem::Requirement
57
+ none: false
54
58
  requirements:
55
59
  - - ">="
56
60
  - !ruby/object:Gem::Version
61
+ hash: 3
57
62
  segments:
58
63
  - 0
59
64
  version: "0"
60
65
  required_rubygems_version: !ruby/object:Gem::Requirement
66
+ none: false
61
67
  requirements:
62
68
  - - ">="
63
69
  - !ruby/object:Gem::Version
70
+ hash: 3
64
71
  segments:
65
72
  - 0
66
73
  version: "0"
67
74
  requirements: []
68
75
 
69
76
  rubyforge_project:
70
- rubygems_version: 1.3.6
77
+ rubygems_version: 1.3.7
71
78
  signing_key:
72
79
  specification_version: 3
73
80
  summary: Genghis is a mongoDB configuration and resilience framework