Skip to content

Instantly share code, notes, and snippets.

@zeevallin
Created February 15, 2015 07:19
Show Gist options
  • Save zeevallin/a7fb2a89a77e8940f797 to your computer and use it in GitHub Desktop.
Save zeevallin/a7fb2a89a77e8940f797 to your computer and use it in GitHub Desktop.
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