Module: Riagent::Configuration
- Included in:
- Riagent
- Defined in:
- lib/riagent/configuration.rb
Instance Method Summary collapse
- #config ⇒ Object
- #config=(value) ⇒ Object
-
#config_for(environment = :development) ⇒ Hash
Return a configuration hash for a given environment.
-
#init_clients(environment = :development) ⇒ Object
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.
- #init_riak_client(env_config) ⇒ Object
- #load_config_file(config_file_path) ⇒ Object
-
#riak_client ⇒ Riak::Client
The Riak client for the current thread.
-
#riak_client=(value) ⇒ Object
Sets the Riak client for the current thread.
Instance Method Details
#config ⇒ Object
27 28 29 |
# File 'lib/riagent/configuration.rb', line 27 def config @config ||= {} end |
#config=(value) ⇒ Object
31 32 33 |
# File 'lib/riagent/configuration.rb', line 31 def config=(value) @config = value end |
#config_for(environment = :development) ⇒ Hash
Return a configuration hash for a given environment
38 39 40 41 42 43 44 45 46 47 48 49 |
# 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) ⇒ Object
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
63 64 65 66 |
# 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) ⇒ Object
52 53 54 55 56 |
# 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) ⇒ Object
68 69 70 71 72 |
# File 'lib/riagent/configuration.rb', line 68 def load_config_file(config_file_path) config_file = File.(config_file_path) config_hash = YAML.load(ERB.new(File.read(config_file)).result) self.config = config_hash end |
#riak_client ⇒ Riak::Client
Returns The Riak client for the current thread.
75 76 77 78 79 80 81 |
# 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) ⇒ Object
Sets the Riak client for the current thread.
85 86 87 |
# File 'lib/riagent/configuration.rb', line 85 def riak_client=(value) Thread.current[:riak_client] = value end |