module Rails::Sharding::ShardableModel::ClassMethodsOverrides
Module that includes all class methods that will be overriden on the model class when Rails::Sharding::ShardableModel
is included
Public Class Methods
dinamically saves original methods with prefix “original_” and overrides then with the methods with prefix “sharded_”
# File lib/rails/sharding/shardable_model.rb, line 22 def self.extended(klass) self.instance_methods.each do |sharded_method_name| method_name = sharded_method_name.to_s.match(/sharded_(.+)/)[1].to_sym klass.singleton_class.instance_eval do alias_method "original_#{method_name}".to_sym, method_name alias_method method_name, sharded_method_name end end end
Public Instance Methods
@overrides ActiveRecord::ConnectionHandling#clear_active_connections!
# File lib/rails/sharding/shardable_model.rb, line 85 def sharded_clear_active_connections! if ShardThreadRegistry.connecting_to_master? return original_clear_active_connections! else return ConnectionHandler.connection_handler.clear_active_connections! end end
@overrides ActiveRecord::ConnectionHandling#clear_all_connections!
# File lib/rails/sharding/shardable_model.rb, line 103 def sharded_clear_all_connections! if ShardThreadRegistry.connecting_to_master? return original_clear_all_connections! else return ConnectionHandler.connection_handler.clear_all_connections! end end
@overrides ActiveRecord::ConnectionHandling#clear_reloadable_connections!
# File lib/rails/sharding/shardable_model.rb, line 94 def sharded_clear_reloadable_connections! if ShardThreadRegistry.connecting_to_master? return original_clear_reloadable_connections! else return ConnectionHandler.connection_handler.clear_reloadable_connections! end end
@overrides ActiveRecord::ConnectionHandling#connected?
# File lib/rails/sharding/shardable_model.rb, line 56 def sharded_connected? if ShardThreadRegistry.connecting_to_master? return original_connected? else return ConnectionHandler.connected?(*ShardThreadRegistry.current_shard_group_and_name) end end
@overrides ActiveRecord::ConnectionHandling#connection_pool
# File lib/rails/sharding/shardable_model.rb, line 34 def sharded_connection_pool ShardThreadRegistry.notify_connection_retrieved if ShardThreadRegistry.connecting_to_master? return original_connection_pool else return ConnectionHandler.connection_pool(*ShardThreadRegistry.current_shard_group_and_name) end end
@overrides ActiveRecord::ConnectionHandling#establish_connection In the case we are connecting to a shard, ignore spec parameter and use what is in ShardThreadRegistry
instead
# File lib/rails/sharding/shardable_model.rb, line 76 def sharded_establish_connection(spec=nil) if ShardThreadRegistry.connecting_to_master? return original_establish_connection(spec) else return ConnectionHandler.establish_connection(*ShardThreadRegistry.current_shard_group_and_name) end end
@overrides ActiveRecord::ConnectionHandling#flush_idle_connections!
# File lib/rails/sharding/shardable_model.rb, line 112 def sharded_flush_idle_connections! if ShardThreadRegistry.connecting_to_master? return original_flush_idle_connections! else return ConnectionHandler.connection_handler.flush_idle_connections! end end
@overrides ActiveRecord::ConnectionHandling#remove_connection (only if no parameters are passed)
# File lib/rails/sharding/shardable_model.rb, line 65 def sharded_remove_connection(klass=nil) if ShardThreadRegistry.connecting_to_master? || klass return klass ? original_remove_connection(klass) : original_remove_connection else return ConnectionHandler.remove_connection(*ShardThreadRegistry.current_shard_group_and_name) end end
@overrides ActiveRecord::ConnectionHandling#retrieve_connection
# File lib/rails/sharding/shardable_model.rb, line 45 def sharded_retrieve_connection ShardThreadRegistry.notify_connection_retrieved if ShardThreadRegistry.connecting_to_master? return original_retrieve_connection else return ConnectionHandler.retrieve_connection(*ShardThreadRegistry.current_shard_group_and_name) end end