class Makara::ConfigParser
Constants
- DEFAULTS
Attributes
makara_config[R]
Public Class Methods
merge_and_resolve_default_url_config(config)
click to toggle source
NOTE: url format must be, e.g. url: mysql2://… NOT url: mysql2_makara://… since the '_' in the protocol (mysql2_makara) makes the URI invalid NOTE: Does not use ENV
# File lib/makara/config_parser.rb, line 128 def self.merge_and_resolve_default_url_config(config) if ENV['DATABASE_URL'] Makara::Logging::Logger.log "Please rename DATABASE_URL to use in the database.yml", :warn end return config unless config.key?(:url) url = config[:url] url_config = ConnectionUrlResolver.new(url).to_hash url_config = url_config.symbolize_keys url_config.delete(:adapter) config.delete(:url) config.update(url_config) end
new(config)
click to toggle source
# File lib/makara/config_parser.rb, line 144 def initialize(config) @config = config.symbolize_keys @makara_config = DEFAULTS.merge(@config[:makara] || {}) @makara_config = @makara_config.symbolize_keys @id = sanitize_id(@makara_config[:id]) end
Public Instance Methods
id()
click to toggle source
# File lib/makara/config_parser.rb, line 151 def id @id ||= begin sorted = recursive_sort(@config) Digest::MD5.hexdigest(sorted.to_s) end end
master_configs()
click to toggle source
# File lib/makara/config_parser.rb, line 158 def master_configs all_configs .select { |config| config[:role] == 'master' } .map { |config| config.except(:role) } end
slave_configs()
click to toggle source
# File lib/makara/config_parser.rb, line 164 def slave_configs all_configs .reject { |config| config[:role] == 'master' } .map { |config| config.except(:role) } end
Protected Instance Methods
all_configs()
click to toggle source
# File lib/makara/config_parser.rb, line 172 def all_configs @makara_config[:connections].map do |connection| base_config.merge(makara_config.except(:connections)) .merge(connection.symbolize_keys) end end
base_config()
click to toggle source
# File lib/makara/config_parser.rb, line 179 def base_config @base_config ||= DEFAULTS.merge(@config).except(:makara) end
recursive_sort(thing)
click to toggle source
# File lib/makara/config_parser.rb, line 183 def recursive_sort(thing) return thing.to_s unless thing.include?(Enumerable) thing.map do |part| recursive_sort(part) end thing.sort_by(&:to_s) end
sanitize_id(id)
click to toggle source
# File lib/makara/config_parser.rb, line 193 def sanitize_id(id) return if id.nil? || id.empty? id.gsub(/[\|:]/, '').tap do |sanitized_id| if sanitized_id.size != id.size Makara::Logging::Logger.log "Proxy id '#{id}' changed to '#{sanitized_id}'", :warn end end end