Module: Genghis::ProxyMethods::ClassMethods

Defined in:
lib/genghis.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



187
188
189
190
191
# File 'lib/genghis.rb', line 187

def method_missing(method, * args, & block)
  protect_from_exception do
    Guardian.make_safe(@protected_class.__send__(method, * args, & block))
  end
end

Instance Attribute Details

#protected_classObject

Returns the value of attribute protected_class.



171
172
173
# File 'lib/genghis.rb', line 171

def protected_class
  @protected_class
end

Instance Method Details

#allocateObject



193
194
195
# File 'lib/genghis.rb', line 193

def allocate
  @protected_class.allocate
end

#fix_broken_connectionObject



223
224
225
226
227
228
229
# File 'lib/genghis.rb', line 223

def fix_broken_connection
  Genghis.reconnect
  if defined?(MongoMapper)
    MongoMapper.connection = Genghis.connection
    MongoMapper.database   = Genghis.databases['mongo_mapper']
  end
end

#protect_from_exception(&block) ⇒ Object



201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/genghis.rb', line 201

def protect_from_exception(& block)
  success     = false
  max_retries = Genghis.max_retries
  retries     = 0
  rv          = nil
  while !success
    begin
      rv      = yield
      success = true
    rescue Mongo::ConnectionFailure => ex
      if Genghis.failure_callback
        Genghis.failure_callback.call(ex, Genghis.connection)
      end
      retries += 1
      raise ex if retries > max_retries
      fix_broken_connection
      sleep(Genghis.sleep_between_retries)
    end
  end
  rv
end

#protected?(clazz) ⇒ Boolean

Returns:

  • (Boolean)


183
184
185
# File 'lib/genghis.rb', line 183

def protected?(clazz)
  @@protected_classes.include? clazz
end

#protects(clazz) ⇒ Object



173
174
175
176
177
# File 'lib/genghis.rb', line 173

def protects(clazz)
  Guardian.add(clazz)
  Guardian.add_protected_class(self, clazz)
  @protected_class= clazz
end

#safe?Boolean

Returns:

  • (Boolean)


197
198
199
# File 'lib/genghis.rb', line 197

def safe?
  true
end