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.
278 279 280 281 |
# File 'lib/archipelago/disco.rb', line 278 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.
293 294 295 296 297 298 299 300 301 |
# File 'lib/archipelago/disco.rb', line 293 def method_missing(meth, *args, &block) if @hash.respond_to?(meth) synchronize do @hash.send(meth, *args, &block) end else super(meth, *args, &block) end end |
Instance Attribute Details
#hash ⇒ Object (readonly)
Returns the value of attribute hash.
275 276 277 |
# File 'lib/archipelago/disco.rb', line 275 def hash @hash end |
Instance Method Details
#get_services(match) ⇒ Object
Find all containing services matching match.
305 306 307 308 309 310 311 |
# File 'lib/archipelago/disco.rb', line 305 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.
285 286 287 288 289 |
# File 'lib/archipelago/disco.rb', line 285 def merge(sd) rval = @hash.clone rval.merge!(sd.hash) ServiceLocker.new(rval) end |
#validate! ⇒ Object
Remove all non-valid services.
315 316 317 318 319 |
# File 'lib/archipelago/disco.rb', line 315 def validate! self.clone.each do |service_id, service_data| self.delete(service_id) unless service_data.valid? end end |