Class: Ki::ServiceRegistry
Defined Under Namespace
Classes: ServiceList
Instance Attribute Summary collapse
-
#by_parent ⇒ Object
readonly
Returns the value of attribute by_parent.
Instance Method Summary collapse
- #clear ⇒ Object
- #find(url, value = nil) ⇒ Object
- #find!(url, value = nil) ⇒ Object
-
#initialize ⇒ ServiceRegistry
constructor
A new instance of ServiceRegistry.
- #register(*args) ⇒ Object
Methods inherited from Hash
Constructor Details
#initialize ⇒ ServiceRegistry
Returns a new instance of ServiceRegistry.
23 24 25 26 |
# File 'lib/util/service_registry.rb', line 23 def initialize @monitor = Monitor.new @by_parent = {} end |
Instance Attribute Details
#by_parent ⇒ Object (readonly)
Returns the value of attribute by_parent.
21 22 23 |
# File 'lib/util/service_registry.rb', line 21 def by_parent @by_parent end |
Instance Method Details
#clear ⇒ Object
71 72 73 74 75 76 |
# File 'lib/util/service_registry.rb', line 71 def clear @monitor.synchronize do @by_parent.clear super end end |
#find(url, value = nil) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/util/service_registry.rb', line 46 def find(url, value=nil) @monitor.synchronize do if include?(url) self[url] elsif @by_parent.include?(url) services = @by_parent[url] if services if value services = services.select { |id, service| service.supports?(value) } end services = ServiceList.new.concat(services) end services end end end |
#find!(url, value = nil) ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/util/service_registry.rb', line 63 def find!(url, value=nil) found = find(url, value) if found.nil? raise "Could not resolve '#{url}'" end found end |
#register(*args) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/util/service_registry.rb', line 28 def register(*args) @monitor.synchronize do case args.size when 1 args.first.each_pair do |url, clazz| register(url, clazz) end when 2 url, clazz = args self[url]=clazz (@by_parent[File.dirname(url)]||=Array.new) << args else raise "Not supported '#{args.inspect}'" end end self end |