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
38 39 40 |
# File 'lib/active_record_shards/configuration_parser.rb', line 38 def configurations_with_shard_explosion=(conf) self.configurations_without_shard_explosion = explode(conf) end |
.expand_child!(parent, child) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/active_record_shards/configuration_parser.rb', line 30 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
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/active_record_shards/configuration_parser.rb', line 7 def explode(conf) conf = conf.deep_dup 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
42 43 44 45 46 47 48 |
# File 'lib/active_record_shards/configuration_parser.rb', line 42 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 |