class Simple::Sharding::Core
Public Class Methods
config(env=Rails.env)
click to toggle source
configuration
# File lib/simple/sharding/core.rb, line 25 def self.config(env=Rails.env) @@db_config ||= YAML.load_file(Config.config(:shard_config_file)) env_config = @@db_config[env] return env_config if env_config # error raise "No correct config for env: #{env}." end
sharding(shard_id) { || ... }
click to toggle source
block support
# File lib/simple/sharding/core.rb, line 9 def self.sharding(shard_id) begin raise "no shard group #{shard_id} found in pool." if ConnectionHandler.check(shard_id) ShardThreadRegistry.push_current_shard(shard_id) yield ensure # Releases connections in case user left some connection in the reserved state # (by calling retrieve_connection instead of with_connection). Also, using # normal activerecord queries leaves a connection in the reserved state # Obs: don't do this with a master database connection ConnectionHandler.connection_pool(shard_id).release_connection if !shard_id.blank? end end
Public Instance Methods
setup() { |Config| ... }
click to toggle source
# File lib/simple/sharding/core.rb, line 34 def setup if block_given? yield Config end ConnectionHandler.connect_all ActiveRecordExtensions.extend_active_record_scope end