Module: ConsulDo

Defined in:
lib/consul_do.rb,
lib/consul_do/elect.rb,
lib/consul_do/config.rb,
lib/consul_do/version.rb

Defined Under Namespace

Classes: Config, Elect

Constant Summary collapse

VERSION =
"0.1.2"

Class Method Summary collapse

Class Method Details

.configObject



8
9
10
# File 'lib/consul_do.rb', line 8

def self.config
  @config ||= Config.new
end

.configure! {|config| ... } ⇒ Object

Yields:



12
13
14
15
# File 'lib/consul_do.rb', line 12

def self.configure!
  @config = Config.new
  yield config
end

.electObject



17
18
19
# File 'lib/consul_do.rb', line 17

def self.elect
  @elect ||= Elect.new
end

.elect!Object



21
22
23
# File 'lib/consul_do.rb', line 21

def self.elect!
  @elect = Elect.new
end

.http_get(dest_url) ⇒ Object



31
32
33
# File 'lib/consul_do.rb', line 31

def self.http_get(dest_url)
  log "http_get", config.http_client.get_response(URI(dest_url))
end

.http_put(dest_url, data = nil) ⇒ Object



25
26
27
28
29
# File 'lib/consul_do.rb', line 25

def self.http_put(dest_url, data = nil)
  uri = URI.parse(dest_url)
  request = config.http_client.new(uri.host, uri.port)
  log "http_put", request.send_request('PUT', "#{ [uri.path, uri.query].compact.join('?') }", data.to_json, {'Content-type' => 'application/json'})
end

.log(msg, retval) ⇒ Object



35
36
37
38
# File 'lib/consul_do.rb', line 35

def self.log(msg, retval)
  puts [msg,retval.to_s].join(":\n  ") if config.verbose
  retval
end