class OhlohScm::Validation

Attributes

errors[R]

Public Class Methods

new(core) click to toggle source
# File lib/ohloh_scm/validation.rb, line 12
def initialize(core)
  @core = core
end

Public Instance Methods

validate() click to toggle source
# File lib/ohloh_scm/validation.rb, line 16
def validate
  validate_attributes
  Timeout.timeout(timeout_interval) { validate_server_connection } if @errors.none?
end

Private Instance Methods

branch_name_errors() click to toggle source

rubocop:enable Metrics/AbcSize

# File lib/ohloh_scm/validation.rb, line 50
def branch_name_errors
  if scm.branch_name.length > 80
    [:branch_name, 'The branch name must not be longer than 80 characters.']
  elsif !scm.branch_name.match?(/^[\w^\-\+\.\/\ ]+$/)
    [:branch_name, "The branch name may contain only letters, numbers, \
       spaces, and the special characters '_', '-', '+', '/', '^', and '.'"]
  end
end
password_errors() click to toggle source
# File lib/ohloh_scm/validation.rb, line 67
def password_errors
  if scm.password.length > 32
    [:password, 'The password must not be longer than 32 characters.']
  elsif !scm.password.match?(/^[\w!@\#$%^&*\(\)\{\}\[\]\;\?\|\+\-\=]*$/)
    [:password, 'The password contains illegal characters']
  end
end
public_url_regex() click to toggle source
# File lib/ohloh_scm/validation.rb, line 79
def public_url_regex; end
timeout_interval() click to toggle source
# File lib/ohloh_scm/validation.rb, line 75
def timeout_interval
  ENV['SCM_URL_VALIDATION_TIMEOUT']&.to_i || 60
end
url_errors() click to toggle source

rubocop:disable Metrics/AbcSize

# File lib/ohloh_scm/validation.rb, line 37
def url_errors
  error = if scm.url.nil? || scm.url.empty?
            "The URL can't be blank."
          elsif scm.url.length > 120
            'The URL must not be longer than 120 characters.'
          elsif !scm.url.match?(public_url_regex)
            'The URL does not appear to be a valid server connection string.'
          end

  [:url, error] if error
end
username_errors() click to toggle source
# File lib/ohloh_scm/validation.rb, line 59
def username_errors
  if scm.username.length > 32
    [:username, 'The username must not be longer than 32 characters.']
  elsif !scm.username.match?(/^\w*$/)
    [:username, 'The username may contain only A-Z, a-z, 0-9, and underscore (_)']
  end
end
validate_attributes() click to toggle source

rubocop:disable Metrics/AbcSize

# File lib/ohloh_scm/validation.rb, line 26
def validate_attributes
  @errors = []
  @errors << url_errors
  @errors << branch_name_errors unless scm.branch_name.to_s.empty?
  @errors << username_errors if scm.username
  @errors << password_errors if scm.password
  @errors.compact!
end
validate_server_connection() click to toggle source
# File lib/ohloh_scm/validation.rb, line 23
def validate_server_connection; end