Class: Ant::Configuration::ServiceManager

Inherits:
Object
  • Object
show all
Extended by:
DRY::ResourceInjector
Defined in:
lib/ant/configs/service_manager.rb

Overview

Allow to autoload configurations into ruby. It allows to implement new plugins.

Direct Known Subclasses

Autoconfigs::Aws

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configs, plugin_subdir = '.') ⇒ ServiceManager

Returns a new instance of ServiceManager.



15
16
17
18
19
# File 'lib/ant/configs/service_manager.rb', line 15

def initialize(configs, plugin_subdir = '.')
  @configs = configs
  @services = {}
  @plugin_subdir = plugin_subdir
end

Instance Attribute Details

#configsObject (readonly)

Returns the value of attribute configs.



13
14
15
# File 'lib/ant/configs/service_manager.rb', line 13

def configs
  @configs
end

Class Method Details

.auto_load!Object



58
59
60
61
62
63
# File 'lib/ant/configs/service_manager.rb', line 58

def self.auto_load!
  configs = Ant::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



67
68
69
# File 'lib/ant/configs/service_manager.rb', line 67

def self.register_plugin(name, type = 'multi')
  register(:plugins, name, type)
end

Instance Method Details

#all_servicesObject



25
26
27
# File 'lib/ant/configs/service_manager.rb', line 25

def all_services
  @services
end

#build_service(name, config) ⇒ Object



54
55
56
# File 'lib/ant/configs/service_manager.rb', line 54

def build_service(name, config)
  Ant::Configuration::Autoconfigs.from_config!(name, config, @plugin_subdir)
end

#configure!Object



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ant/configs/service_manager.rb', line 29

def configure!
  plugins = self.class.resources(:plugins)
  plugins.each do |plug, type|
    next if @configs[plug].nil?

    case type
    when 'unique'
      @services[plug] = Ant::Configuration::Autoconfigs.from_config!(plug, @configs[plug])
    else
      load_service!(plug, @configs[plug])
    end
  end
end

#featuresObject



71
72
73
# File 'lib/ant/configs/service_manager.rb', line 71

def features
  @services['features']
end

#load_service!(name, keys) ⇒ Object



43
44
45
46
47
48
49
50
51
52
# File 'lib/ant/configs/service_manager.rb', line 43

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) ⇒ Object



21
22
23
# File 'lib/ant/configs/service_manager.rb', line 21

def services(cathegory, name)
  @services[cathegory][name].raw
end