Sha256: 35b635cd8b752fb309032db9270220eb93202842c3dbc9147027a623c8b15551
Contents?: true
Size: 1.26 KB
Versions: 2
Compression:
Stored size: 1.26 KB
Contents
module ActiveRecordShards module ConfigurationParser module_function def explode(conf) conf.keys.each do |env_name| env_config = conf[env_name] if shards = env_config.delete('shards') shards.each do |shard_name, shard_conf| expand_child!(env_config, shard_conf) conf["#{env_name}_shard_#{shard_name}"] = shard_conf end end end conf.keys.each do |env_name| env_config = conf[env_name] if slave_conf = env_config.delete('slave') expand_child!(env_config, slave_conf) conf["#{env_name}_slave"] = slave_conf end end conf end def expand_child!(parent, child) parent.each do |key, value| unless ['slave', 'shards'].include?(key) || value.is_a?(Hash) child[key] ||= value end end end def configurations_with_shard_explosion=(conf) self.configurations_without_shard_explosion = explode(conf) end def ConfigurationParser.extended(klass) klass.singleton_class.alias_method_chain :configurations=, :shard_explosion if !klass.configurations.nil? && !klass.configurations.empty? klass.configurations = klass.configurations end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
active_record_shards-2.0.0.beta2 | lib/active_record_shards/configuration_parser.rb |
active_record_shards-2.0.0.beta1 | lib/active_record_shards/configuration_parser.rb |