Sha256: 54b025c7aeb8f598028cd60ac00a4f51c9e50fbfa08f8dd65e67beb5ee05f590

Contents?: true

Size: 1.35 KB

Versions: 4

Compression:

Stored size: 1.35 KB

Contents

require_relative '../models/app_fields'
require_relative '../models/service_definition'

module Longleaf
  # Manager which loads and provides access to Longleaf::ServiceDefinition objects
  class ServiceDefinitionManager
    SF ||= Longleaf::ServiceFields
    AF ||= Longleaf::AppFields

    # Hash containing the set of configured services, represented as {ServiceDefinition} objects
    attr_reader :services

    # @param config [Hash] hash representation of the application configuration
    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
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
longleaf-1.1.1 lib/longleaf/services/service_definition_manager.rb
longleaf-1.1.0 lib/longleaf/services/service_definition_manager.rb
longleaf-1.0.0 lib/longleaf/services/service_definition_manager.rb
longleaf-0.3.0 lib/longleaf/services/service_definition_manager.rb