module Riagent::Configuration
Public Instance Methods
config()
click to toggle source
# File lib/riagent/configuration.rb, line 27 def config @config ||= {} end
config=(value)
click to toggle source
# File lib/riagent/configuration.rb, line 31 def config=(value) @config = value end
config_for(environment=:development)
click to toggle source
Return a configuration hash for a given environment @param [Symbol] environment Environment for which to load the client configs @return [Hash]
# File lib/riagent/configuration.rb, line 38 def config_for(environment=:development) if self.config.present? env_config = self.config[environment.to_s] else env_config = { 'host' => ENV['RIAK_HOST'], 'http_port' => ENV['RIAK_HTTP_PORT'], 'pb_port' => ENV['RIAK_PB_PORT'] } end env_config end
init_clients(environment=:development)
click to toggle source
Initialize a Riagent
persistence client for a given environment Either called explicitly (see test/test_helper.rb for example usage) or called by Rails through the ‘riagent.configure_rails_initialization’ initializer in lib/railtie.rb @param [Symbol] environment
# File lib/riagent/configuration.rb, line 63 def init_clients(environment=:development) env_config = self.config_for(environment) self.init_riak_client(env_config) end
init_riak_client(env_config)
click to toggle source
@param [Hash] env_config Configuration
hash for a given environment
# File lib/riagent/configuration.rb, line 52 def init_riak_client(env_config) # client = Riak::Client.new host: env_config['host'], pb_port: env_config['pb_port'], protocol: 'pbc' client = Riak::Client.new host: env_config['host'], pb_port: env_config['pb_port'] self.riak_client = client end
load_config_file(config_file_path)
click to toggle source
# File lib/riagent/configuration.rb, line 68 def load_config_file(config_file_path) config_file = File.expand_path(config_file_path) config_hash = YAML.load(ERB.new(File.read(config_file)).result) self.config = config_hash end
riak_client()
click to toggle source
@return [Riak::Client] The Riak client for the current thread.
# File lib/riagent/configuration.rb, line 75 def riak_client unless Thread.current[:riak_client] # Re-initialize client self.init_riak_client(self.config_for(Rails.env)) end Thread.current[:riak_client] end
riak_client=(value)
click to toggle source
Sets the Riak client for the current thread. @param [Riak::Client] value the client
# File lib/riagent/configuration.rb, line 85 def riak_client=(value) Thread.current[:riak_client] = value end