Class: ConsulDo::Config
- Inherits:
-
Object
- Object
- ConsulDo::Config
- Defined in:
- lib/consul_do/config.rb
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#http_proxy ⇒ Object
Returns the value of attribute http_proxy.
-
#key ⇒ Object
Returns the value of attribute key.
-
#port ⇒ Object
Returns the value of attribute port.
-
#token ⇒ Object
Returns the value of attribute token.
-
#verbose ⇒ Object
Returns the value of attribute verbose.
Instance Method Summary collapse
- #http_client ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #net_http_proxy ⇒ Object
- #parse ⇒ Object
- #proxy ⇒ Object
- #session_name ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
8 9 10 11 12 13 14 |
# File 'lib/consul_do/config.rb', line 8 def initialize @host = 'localhost' @port = '8500' @key = 'consul_do' @http_proxy = ENV['http_proxy'] || ENV['HTTP_PROXY'] parse end |
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
6 7 8 |
# File 'lib/consul_do/config.rb', line 6 def host @host end |
#http_proxy ⇒ Object
Returns the value of attribute http_proxy.
6 7 8 |
# File 'lib/consul_do/config.rb', line 6 def http_proxy @http_proxy end |
#key ⇒ Object
Returns the value of attribute key.
6 7 8 |
# File 'lib/consul_do/config.rb', line 6 def key @key end |
#port ⇒ Object
Returns the value of attribute port.
6 7 8 |
# File 'lib/consul_do/config.rb', line 6 def port @port end |
#token ⇒ Object
Returns the value of attribute token.
6 7 8 |
# File 'lib/consul_do/config.rb', line 6 def token @token end |
#verbose ⇒ Object
Returns the value of attribute verbose.
6 7 8 |
# File 'lib/consul_do/config.rb', line 6 def verbose @verbose end |
Instance Method Details
#http_client ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/consul_do/config.rb', line 44 def http_client if proxy.host && proxy.port ConsulDo.log "http_client", net_http_proxy else ConsulDo.log "http_client", Net::HTTP end end |
#net_http_proxy ⇒ Object
40 41 42 |
# File 'lib/consul_do/config.rb', line 40 def net_http_proxy Net::HTTP.Proxy(proxy.host, proxy.port, proxy.user, proxy.password) end |
#parse ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/consul_do/config.rb', line 16 def parse OptionParser.new do |opts| opts. = "Usage: consul-do OPTIONS" opts.on("-k", "--key KEY=consul_do", "Coordination key"){ |v| self.key = v } opts.on("-h", "--consul-host HOST=localhost", "Consul hostname"){ |v| self.host = v } opts.on("-p", "--consul-port PORT=8500", "Consul port"){ |v| self.port = v } opts.on("-t", "--token TOKEN", "ACL Token"){ |v| self.token = v } opts.on("--http_proxy http://HOST:PORT", "Use supplied proxy instead of ENV "){ |v| self.http_proxy = v } opts.on("-v", "--verbose", "Consul port"){ |v| self.verbose = v } end.parse! end |
#proxy ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/consul_do/config.rb', line 28 def proxy begin URI.parse(http_proxy) rescue URI::InvalidURIError URI::Generic.new(nil,nil,nil,nil,nil,nil,nil,nil,nil) end end |
#session_name ⇒ Object
36 37 38 |
# File 'lib/consul_do/config.rb', line 36 def session_name "consul-do_#{key}_session" end |