class Envirobly::Config

def validate_services(services)

def validate_services(services)
  unless services.is_a?(Hash)
    @errors << "`services` key must be a hash."
    return
  end
  services.each do |name, service|
    unless name =~ NAME_FORMAT
      @errors << "`#{name}` is not a valid service name. Use aplhanumeric characters, dash, underscore, slash or dot."
    end
    unless service.is_a?(Hash)
      @errors << "Service `#{name}` must be a hash."
      next
    end
    service.each do |attribute, value|
      unless VALID_SERVICE_KEYS.include?(attribute)
        @errors << "Service `#{name}` attribute `#{attribute}` is not a valid attribute."
      end
      if attribute == :build
        unless value =~ BUILD_VALUE_FORMAT
          @errors << "Service `#{name}` attribute `#{attribute}` format needs to be a number prefixed with letter \"v\", for example \"v1\"."
        end
      end
    end
    BUILD_DEFAULTS.each do |attribute, options|
      value = service.fetch(attribute, options.first)
      unless @commit.public_send(options.second, value)
        @errors << "Service `#{name}` specifies `#{attribute}` as `#{value}` which doesn't exist in this commit."
      end
    end
    service.fetch(:env, {}).each do |key, value|
      if value.is_a?(Hash) && value.has_key?(:file)
        unless @commit.file_exists?(value.fetch(:file))
          @errors << "Environment variable `#{key}` referring to a file `#{value.fetch(:file)}` doesn't exist in this commit."
        end
      end
    end
  end
end