Module: Vidocq
- Defined in:
- lib/vidocq.rb,
lib/vidocq/cache.rb,
lib/vidocq/railtie.rb,
lib/vidocq/version.rb,
lib/vidocq/connection.rb
Defined Under Namespace
Classes: Cache, Connection, NoEndpointError, NoResponseError, Railtie
Constant Summary collapse
- VERSION =
"0.0.7"
Class Method Summary collapse
- .logger ⇒ Object
- .logger=(new_logger) ⇒ Object
-
.new(sid, version, opts = {}) ⇒ Object
Connection factory.
-
.services(connect_string = nikjl) ⇒ Object
Lists all the services, versions and instances in an hierarcical format like the following:.
Class Method Details
.logger ⇒ Object
20 21 22 |
# File 'lib/vidocq.rb', line 20 def self.logger @logger ||= Logger.new(STDOUT) end |
.logger=(new_logger) ⇒ Object
16 17 18 |
# File 'lib/vidocq.rb', line 16 def self.logger=(new_logger) @logger = new_logger end |
.new(sid, version, opts = {}) ⇒ Object
Connection factory
12 13 14 |
# File 'lib/vidocq.rb', line 12 def self.new(sid, version, opts = {}) Connection.new(sid, version, opts || {}) end |
.services(connect_string = nikjl) ⇒ Object
Lists all the services, versions and instances in an hierarcical format like the following:
[
{:name => 'fooservice', :versions =>
[
{:number => '0.1', :instances =>
[
{:endpoint => 'http://198.0.0.1:8900/foo'}, ...
]
}, ...
]
}, ...
]
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/vidocq.rb', line 38 def self.services(connect_string = nikjl) base_path = "/companybook/services" ZK.open(connect_string || 'localhost:2181') do |zk| return [] unless zk.exists?(base_path) return zk.children(base_path).collect do |service| service_path = base_path + '/' + service versions = zk.children(service_path).collect do |version| version_path = service_path + '/' + version instances = zk.children(version_path).collect do |instance| JSON.parse(zk.get(version_path + '/' + instance).first) end {:number => version, :instances => instances} end {:name => service, :versions => versions} end end end |