Class: Longleaf::ServiceDefinitionManager

Inherits:
Object
  • Object
show all
Defined in:
lib/longleaf/services/service_definition_manager.rb

Overview

Manager which loads and provides access to Longleaf::ServiceDefinition objects

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ ServiceDefinitionManager

Returns a new instance of ServiceDefinitionManager.

Parameters:

  • config (Hash)

    hash representation of the application configuration

Raises:

  • (ArgumentError)


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/longleaf/services/service_definition_manager.rb', line 14

def initialize(config)
  raise ArgumentError.new("Configuration must be provided") if config.nil? || config.empty?

  services_config = config[AF::SERVICES]
  raise ArgumentError.new("Services configuration must be provided") if services_config.nil?

  @services = Hash.new
  config[AF::SERVICES].each do |name, properties|
    work_script = properties.delete(SF::WORK_SCRIPT)
    work_class = properties.delete(SF::WORK_CLASS)
    frequency = properties.delete(SF::FREQUENCY)
    delay = properties.delete(SF::DELAY)
    service = Longleaf::ServiceDefinition.new(
        name: name,
        work_script: work_script,
        work_class: work_class,
        frequency: frequency,
        delay: delay,
        properties: properties)

    @services[name] = service
  end
  @services.freeze
end

Instance Attribute Details

#servicesObject (readonly)

Hash containing the set of configured services, represented as Longleaf::ServiceDefinition objects



11
12
13
# File 'lib/longleaf/services/service_definition_manager.rb', line 11

def services
  @services
end