class OhlohScm::Validation
Attributes
Public Class Methods
Public Instance Methods
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
Source
# 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
rubocop:enable Metrics/AbcSize
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
Source
# File lib/ohloh_scm/validation.rb, line 75 def timeout_interval ENV['SCM_URL_VALIDATION_TIMEOUT']&.to_i || 60 end
Source
# 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 > 200 'The URL must not be longer than 200 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
rubocop:disable Metrics/AbcSize
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
Source
# 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
rubocop:disable Metrics/AbcSize
Source
# File lib/ohloh_scm/validation.rb, line 23 def validate_server_connection; end