Class: PublicIp::Service::Registry
- Inherits:
-
Object
- Object
- PublicIp::Service::Registry
- Includes:
- Singleton
- Defined in:
- lib/public_ip/service/registry.rb
Instance Attribute Summary collapse
-
#service_database ⇒ Object
readonly
Returns the value of attribute service_database.
Class Method Summary collapse
- .[](service) ⇒ Object
- .available_services ⇒ Object
- .random_service ⇒ Object
- .register_service(service_class) ⇒ Object
Instance Method Summary collapse
Instance Attribute Details
#service_database ⇒ Object (readonly)
Returns the value of attribute service_database.
8 9 10 |
# File 'lib/public_ip/service/registry.rb', line 8 def service_database @service_database end |
Class Method Details
.[](service) ⇒ Object
15 16 17 |
# File 'lib/public_ip/service/registry.rb', line 15 def self.[](service) instance[service] end |
.available_services ⇒ Object
23 24 25 |
# File 'lib/public_ip/service/registry.rb', line 23 def self.available_services instance.available_services end |
.random_service ⇒ Object
19 20 21 |
# File 'lib/public_ip/service/registry.rb', line 19 def self.random_service instance.random_service end |
.register_service(service_class) ⇒ Object
10 11 12 13 |
# File 'lib/public_ip/service/registry.rb', line 10 def self.register_service(service_class) return if instance.service_database.key?(service_class.symbol) instance.service_database[service_class.symbol] = service_class end |
Instance Method Details
#[](service) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/public_ip/service/registry.rb', line 27 def [](service) require "public_ip/service/#{service}" service_database[service] rescue LoadError raise PublicIp::UnknownService, "Service #{service} is not a valid service" end |
#available_services ⇒ Object
40 41 42 43 |
# File 'lib/public_ip/service/registry.rb', line 40 def available_services register_all_services service_database end |
#random_service ⇒ Object
34 35 36 37 38 |
# File 'lib/public_ip/service/registry.rb', line 34 def random_service register_all_services service_database.values.sample end |