Sha256: bd85bb6ba133aa13c53f0a7f0a894f5a1c595c586999256526ac79b2ba2bd882

Contents?: true

Size: 1.57 KB

Versions: 3

Compression:

Stored size: 1.57 KB

Contents

require 'pathname'
require 'longleaf/models/service_fields'
require 'longleaf/models/app_fields'
require 'longleaf/errors'
require_relative 'configuration_validator'

module Longleaf
  # Validates application configuration of service definitions
  class ServiceDefinitionValidator < ConfigurationValidator
    SF ||= Longleaf::ServiceFields
    AF ||= Longleaf::AppFields

    # @param config [Hash] hash containing the application configuration
    def initialize(config)
      super(config)
    end

    protected
    # Validates configuration to ensure that it is syntactically correct and does not violate
    # schema requirements.
    # @param config [Hash] hash containing the application configuration
    def validate
      assert("Configuration must be a hash, but a #{@config.class} was provided", @config.class == Hash)
      assert("Configuration must contain a root '#{AF::SERVICES}' key", @config.key?(AF::SERVICES))
      services = @config[AF::SERVICES]
      assert("'#{AF::SERVICES}' must be a hash of services", services.class == Hash)

      services.each do |name, properties|
        register_on_failure do
          assert("Name of service definition must be a string, but was of type #{name.class}", name.instance_of?(String))
          assert("Service definition '#{name}' must be a hash, but a #{properties.class} was provided", properties.is_a?(Hash))

          work_script = properties[SF::WORK_SCRIPT]
          assert("Service definition '#{name}' must specify a '#{SF::WORK_SCRIPT}' property", !work_script.nil? && !work_script.empty?)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

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