Class: Grenache::Base
- Inherits:
-
Object
- Object
- Grenache::Base
- Includes:
- Configurable
- Defined in:
- lib/grenache/base.rb
Instance Method Summary collapse
-
#announce(key, port, opts = {}, &block) ⇒ Object
Announce a specific service ‘key` available on specific `port` passed block is called when the announce is sent.
-
#initialize(params = {}) ⇒ Base
constructor
Initialize can accept custom configuration parameters.
-
#lookup(key, opts = {}) {|addr| ... } ⇒ Object
Lookup for a specific service ‘key` passed block is called with the result values in case of `http` backend it return the result directly.
Methods included from Configurable
Constructor Details
#initialize(params = {}) ⇒ Base
Initialize can accept custom configuration parameters
16 17 18 |
# File 'lib/grenache/base.rb', line 16 def initialize(params = {}) @configuration = Configuration.new(params) end |
Instance Method Details
#announce(key, port, opts = {}, &block) ⇒ Object
Announce a specific service ‘key` available on specific `port` passed block is called when the announce is sent
38 39 40 41 42 43 44 45 46 |
# File 'lib/grenache/base.rb', line 38 def announce(key, port, opts={}, &block) payload = [key,port] link.send 'announce', payload, opts, &block if config.auto_announce periodically(config.auto_announce_interval) do link.send 'announce', payload, opts, &block end end end |
#lookup(key, opts = {}) {|addr| ... } ⇒ Object
Lookup for a specific service ‘key` passed block is called with the result values in case of `http` backend it return the result directly
24 25 26 27 28 29 30 31 |
# File 'lib/grenache/base.rb', line 24 def lookup(key, opts={}, &block) unless addr = cache.has?(key) addr = link.send('lookup', key, opts, &block) cache.save(key, addr) end yield addr if block_given? addr end |