Module: ActiveRecordShards::ConfigurationParser
- Included in:
- ActiveRecord::Base
- Defined in:
- lib/active_record_shards/configuration_parser.rb
Class Method Summary collapse
- .configurations_with_shard_explosion=(conf) ⇒ Object
- .expand_child!(parent, child) ⇒ Object
- .explode(conf) ⇒ Object
- .extended(klass) ⇒ Object
Class Method Details
.configurations_with_shard_explosion=(conf) ⇒ Object
34 35 36 |
# File 'lib/active_record_shards/configuration_parser.rb', line 34 def configurations_with_shard_explosion=(conf) self.configurations_without_shard_explosion = explode(conf) end |
.expand_child!(parent, child) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/active_record_shards/configuration_parser.rb', line 26 def (parent, child) parent.each do |key, value| unless ['slave', 'shards'].include?(key) || value.is_a?(Hash) child[key] ||= value end end end |
.explode(conf) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/active_record_shards/configuration_parser.rb', line 5 def explode(conf) conf.to_a.each do |env_name, env_config| if shards = env_config.delete('shards') env_config['shard_names'] = shards.keys shards.each do |shard_name, shard_conf| (env_config, shard_conf) conf["#{env_name}_shard_#{shard_name}"] = shard_conf end end end conf.to_a.each do |env_name, env_config| if slave_conf = env_config.delete('slave') (env_config, slave_conf) conf["#{env_name}_slave"] = slave_conf end end conf end |
.extended(klass) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/active_record_shards/configuration_parser.rb', line 38 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 |