Created
February 15, 2015 07:19
-
-
Save zeevallin/a7fb2a89a77e8940f797 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Factories | |
module RiakClient | |
def self.call(url) | |
require "uri" | |
uris = url.split(" ").map { |url| URI(url) } | |
uris.map! do |uri| | |
args = {} | |
args[:host] = (Rails.env.development? || Rails.env.test?) ? uri.hostname.gsub(/\-/,"_") : uri.hostname | |
args[:pb_port] = Integer(uri.port) if uri.port | |
args[:authentication] = {} | |
args[:authentication][:username] = CGI.unescape(uri.user) if uri.user | |
args[:authentication][:password] = CGI.unescape(uri.password) if uri.password | |
if uri.query | |
query = Rack::Utils.parse_nested_query(uri.query) | |
args.merge!(query.symbolize_keys) | |
end | |
args | |
end | |
require "riak" | |
Rails.logger.debug("Connecting to Riak nodes #{ uris.map(&:to_s).to_sentence }") | |
return Riak::Client.new nodes: uris | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment