Class: Archipelago::Disco::ServiceLocker
- Inherits:
-
Object
- Object
- Archipelago::Disco::ServiceLocker
- Includes:
- Current::Synchronized, Current::ThreadedCollection
- Defined in:
- lib/archipelago/disco.rb
Overview
A container of services.
Instance Attribute Summary collapse
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
Instance Method Summary collapse
-
#get_services(match) ⇒ Object
Find all containing services matching
match
. -
#initialize(hash = nil) ⇒ ServiceLocker
constructor
A new instance of ServiceLocker.
-
#merge(sd) ⇒ Object
Merge this locker with another.
-
#method_missing(meth, *args, &block) ⇒ Object
Forwards as much as possible to our Hash.
-
#validate! ⇒ Object
Remove all non-valid services.
Methods included from Current::ThreadedCollection
#t_collect, #t_each, #t_reject, #t_select
Methods included from Current::Synchronized
#lock_on, #mon_check_owner, #synchronize_on, #unlock_on
Constructor Details
#initialize(hash = nil) ⇒ ServiceLocker
Returns a new instance of ServiceLocker.
281 282 283 284 |
# File 'lib/archipelago/disco.rb', line 281 def initialize(hash = nil) super @hash = hash || {} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
Forwards as much as possible to our Hash.
296 297 298 299 300 301 302 303 304 305 306 307 308 |
# File 'lib/archipelago/disco.rb', line 296 def method_missing(meth, *args, &block) if @hash.respond_to?(meth) synchronize do if block @hash.send(meth, *args, &block) else @hash.send(meth, *args) end end else super(meth, *args, &block) end end |
Instance Attribute Details
#hash ⇒ Object (readonly)
Returns the value of attribute hash.
278 279 280 |
# File 'lib/archipelago/disco.rb', line 278 def hash @hash end |
Instance Method Details
#get_services(match) ⇒ Object
Find all containing services matching match
.
312 313 314 315 316 317 318 |
# File 'lib/archipelago/disco.rb', line 312 def get_services(match) rval = ServiceLocker.new self.each do |service_id, service_data| rval[service_id] = service_data if service_data.matches?(match) && service_data.valid? end return rval end |
#merge(sd) ⇒ Object
Merge this locker with another.
288 289 290 291 292 |
# File 'lib/archipelago/disco.rb', line 288 def merge(sd) rval = @hash.clone rval.merge!(sd.hash) ServiceLocker.new(rval) end |
#validate! ⇒ Object
Remove all non-valid services.
322 323 324 325 326 |
# File 'lib/archipelago/disco.rb', line 322 def validate! self.clone.each do |service_id, service_data| self.delete(service_id) unless service_data.valid? end end |