Class: Makara::ConfigParser
- Inherits:
-
Object
- Object
- Makara::ConfigParser
- Defined in:
- lib/makara/config_parser.rb
Defined Under Namespace
Classes: ConnectionUrlResolver
Constant Summary collapse
- DEFAULTS =
{ :master_ttl => 5, :blacklist_duration => 30, :sticky => true }
Instance Attribute Summary collapse
-
#makara_config ⇒ Object
readonly
Returns the value of attribute makara_config.
Class Method Summary collapse
-
.merge_and_resolve_default_url_config(config) ⇒ Object
NOTE: url format must be, e.g.
Instance Method Summary collapse
- #id ⇒ Object
-
#initialize(config) ⇒ ConfigParser
constructor
A new instance of ConfigParser.
- #master_configs ⇒ Object
- #slave_configs ⇒ Object
Constructor Details
#initialize(config) ⇒ ConfigParser
Returns a new instance of ConfigParser.
143 144 145 146 147 148 |
# File 'lib/makara/config_parser.rb', line 143 def initialize(config) @config = config.symbolize_keys @makara_config = DEFAULTS.merge(@config[:makara] || {}) @makara_config = @makara_config.symbolize_keys @id = @makara_config[:id] end |
Instance Attribute Details
#makara_config ⇒ Object (readonly)
Returns the value of attribute makara_config.
141 142 143 |
# File 'lib/makara/config_parser.rb', line 141 def makara_config @makara_config end |
Class Method Details
.merge_and_resolve_default_url_config(config) ⇒ Object
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
128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/makara/config_parser.rb', line 128 def self.merge_and_resolve_default_url_config(config) if ENV['DATABASE_URL'] 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 |
Instance Method Details
#id ⇒ Object
151 152 153 154 155 156 |
# 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 ⇒ Object
159 160 161 162 163 |
# File 'lib/makara/config_parser.rb', line 159 def master_configs all_configs .select { |config| config[:role] == 'master' } .map { |config| config.except(:role) } end |
#slave_configs ⇒ Object
166 167 168 169 170 |
# File 'lib/makara/config_parser.rb', line 166 def slave_configs all_configs .reject { |config| config[:role] == 'master' } .map { |config| config.except(:role) } end |