Class: Kybus::Configuration::ServiceManager
- Inherits:
-
Object
- Object
- Kybus::Configuration::ServiceManager
- Extended by:
- DRY::ResourceInjector
- Defined in:
- lib/kybus/configs/service_manager.rb
Overview
Allow to autoload configurations into ruby. It allows to implement new plugins.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#configs ⇒ Object
readonly
Returns the value of attribute configs.
Class Method Summary collapse
- .auto_load! ⇒ Object
-
.register_plugin(name, type = 'multi') ⇒ Object
The type unique is for global configurations as multi is for a hash containing all the objects to be created.
Instance Method Summary collapse
- #all_services ⇒ Object
- #build_service(name, config) ⇒ Object
- #configure! ⇒ Object
- #features ⇒ Object
-
#initialize(configs, plugin_subdir = '.') ⇒ ServiceManager
constructor
A new instance of ServiceManager.
- #load_service!(name, keys) ⇒ Object
- #services(cathegory, name = nil?, , sub = nil) ⇒ Object
Constructor Details
#initialize(configs, plugin_subdir = '.') ⇒ ServiceManager
Returns a new instance of ServiceManager.
15 16 17 18 19 |
# File 'lib/kybus/configs/service_manager.rb', line 15 def initialize(configs, plugin_subdir = '.') @configs = configs @services = {} @plugin_subdir = plugin_subdir end |
Instance Attribute Details
#configs ⇒ Object (readonly)
Returns the value of attribute configs.
13 14 15 |
# File 'lib/kybus/configs/service_manager.rb', line 13 def configs @configs end |
Class Method Details
.auto_load! ⇒ Object
61 62 63 64 65 66 |
# File 'lib/kybus/configs/service_manager.rb', line 61 def self.auto_load! configs = Kybus::Configuration::ConfigurationManager.auto_load! services = new(configs) services.configure! services end |
.register_plugin(name, type = 'multi') ⇒ Object
The type unique is for global configurations as multi is for a hash containing all the objects to be created
70 71 72 |
# File 'lib/kybus/configs/service_manager.rb', line 70 def self.register_plugin(name, type = 'multi') register(:plugins, name, type) end |
Instance Method Details
#all_services ⇒ Object
28 29 30 |
# File 'lib/kybus/configs/service_manager.rb', line 28 def all_services @services end |
#build_service(name, config) ⇒ Object
57 58 59 |
# File 'lib/kybus/configs/service_manager.rb', line 57 def build_service(name, config) Kybus::Configuration::Autoconfigs.from_config!(name, config, @plugin_subdir) end |
#configure! ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/kybus/configs/service_manager.rb', line 32 def configure! plugins = self.class.resources(:plugins) plugins.each do |plug, type| next if @configs[plug].nil? case type when 'unique' @services[plug] = Kybus::Configuration::Autoconfigs.from_config!(plug, @configs[plug]) else load_service!(plug, @configs[plug]) end end end |
#features ⇒ Object
74 75 76 |
# File 'lib/kybus/configs/service_manager.rb', line 74 def features @services['features'] end |
#load_service!(name, keys) ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/kybus/configs/service_manager.rb', line 46 def load_service!(name, keys) return if keys&.empty? services = {} keys.each do |service, config| services[service] = build_service(name, config) end @services[name] = services end |
#services(cathegory, name = nil?, , sub = nil) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/kybus/configs/service_manager.rb', line 21 def services(cathegory, name = nil?, sub = nil) service = @services[cathegory] service = service[name] if service.is_a?(Hash) && name service = service[sub] if service.is_a?(Hash) && sub service.raw end |