class Airbrake::Config::Validator

Validates values of {Airbrake::Config} options.

@api private @since v1.5.0

Constants

REQUIRED_ID_MSG

@return [String]

REQUIRED_KEY_MSG

@return [String]

VALID_ENV_TYPES

@return [Array<Class>] the list of allowed types to configure the

environment option
WRONG_ENV_TYPE_MSG

@return [String]

Attributes

error_message[R]

@return [String] error message, if validator was able to find any errors

in the config

Public Class Methods

new(config) click to toggle source

Validates given config and stores error message, if any errors were found.

@param config [Airbrake::Config] the config to validate

# File lib/airbrake-ruby/config/validator.rb, line 38
def initialize(config)
  @config = config
  @error_message = nil
end

Public Instance Methods

valid_environment?() click to toggle source

@return [Boolean]

# File lib/airbrake-ruby/config/validator.rb, line 61
def valid_environment?
  environment = @config.environment
  valid = VALID_ENV_TYPES.any? { |type| environment.is_a?(type) }

  unless valid
    @error_message = format(WRONG_ENV_TYPE_MSG, environment.class, environment)
  end

  valid
end
valid_project_id?() click to toggle source

@return [Boolean]

# File lib/airbrake-ruby/config/validator.rb, line 45
def valid_project_id?
  valid = @config.project_id.to_i > 0
  @error_message = REQUIRED_ID_MSG unless valid
  valid
end
valid_project_key?() click to toggle source

@return [Boolean]

# File lib/airbrake-ruby/config/validator.rb, line 53
def valid_project_key?
  valid = @config.project_key.is_a?(String) && !@config.project_key.empty?
  @error_message = REQUIRED_KEY_MSG unless valid
  valid
end