lib/consul/extensions/base.rb in consul-ruby-client-0.0.4 vs lib/consul/extensions/base.rb in consul-ruby-client-0.0.5
- old
+ new
@@ -1,10 +1,14 @@
+require 'logger'
+require_relative '../../../lib/consul/client/agent'
+require_relative '../../../lib/consul/client/key_value'
+require_relative '../../../lib/consul/client/session'
module Consul
module Extensions
class Base
-
+ include Consul::Client
# Public: Constructor for this extension. Ensures a global unique ID for this client for a given namespace.
#
# options - (Optional) Hash of Consul Client and extension options.
# options[:data_center] - (Optional) The Consul data center. Default: 'dc1'.
# options[:api_host] - (Optional) The Consul api host to request against. Default: '127.0.0.1'.
@@ -25,15 +29,23 @@
'.extensions'
end
# The Consul Agent Client to use
def agent
- @agent = Agent.new(options)
+ @agent ||= Agent.new(options)
end
# The Key Value Store to use.
def key_value_store
- @kvs = KeyValue.new(options)
+ @kvs ||= KeyValue.new(options)
+ end
+
+ def session
+ @session || Session.new(options)
+ end
+
+ def logger
+ @logger ||= options[:logger] || Logger.new(STDOUT)
end
# TODO Add other clients here.
private