module SchemaHelperMethods
Constants
- RESERVED_OPTIONS
Public Instance Methods
allowed_special_chareters()
click to toggle source
# File lib/password_schema_validator/schema_helper_methods.rb, line 50 def allowed_special_chareters end
dictionary()
click to toggle source
# File lib/password_schema_validator/schema_helper_methods.rb, line 57 def dictionary end
digits(validate, string)
click to toggle source
# File lib/password_schema_validator/schema_helper_methods.rb, line 42 def digits(validate, string) return "must contain digits" if validate && !(/\d+/ =~ string) end
discarded_words(black_listed_words, string)
click to toggle source
# File lib/password_schema_validator/schema_helper_methods.rb, line 53 def discarded_words(black_listed_words, string) return "must not be in the discarded words" if black_listed_words.map(&:downcase).include?(string.downcase) end
invalid_key_error(key)
click to toggle source
# File lib/password_schema_validator/schema_helper_methods.rb, line 75 def invalid_key_error(key) "Invalid key - '" + key.to_s + "' passed to the schema. Provide a valid permitted key." end
invalid_value_type(key, expected_type)
click to toggle source
# File lib/password_schema_validator/schema_helper_methods.rb, line 79 def invalid_value_type(key, expected_type) "'" + key.to_s + "' must be of type " + expected_type.to_s end
lower_case(validate, string)
click to toggle source
# File lib/password_schema_validator/schema_helper_methods.rb, line 34 def lower_case(validate, string) return "must contain lower-case letters" if validate && !(/[a-z]+/ =~ string) end
match_against_schema(record, attr_name, string)
click to toggle source
# File lib/password_schema_validator/schema_helper_methods.rb, line 18 def match_against_schema(record, attr_name, string) options.each do |attribute| key, value = attribute error_msg = send(key, value, string) record.errors.add(attr_name, error_msg, options) if error_msg end end
max_len(maxValue, string)
click to toggle source
# File lib/password_schema_validator/schema_helper_methods.rb, line 30 def max_len(maxValue, string) return "must be maximum " + maxValue.to_s + " charecter long" if string.length > maxValue.to_i end
min_len(minValue, string)
click to toggle source
# File lib/password_schema_validator/schema_helper_methods.rb, line 26 def min_len(minValue, string) return "must be minimum " + minValue.to_s + " charecter long" if string.length < minValue.to_i end
special_charecters(validate, string)
click to toggle source
# File lib/password_schema_validator/schema_helper_methods.rb, line 46 def special_charecters(validate, string) return "must contain special charecters" if validate && !(/[`~\!@#\$%\^\&\*\(\)\-_\=\+\[\{\}\]\\\|;:'",<.>\/\?]+/ =~ string) end
upper_case(validate, string)
click to toggle source
# File lib/password_schema_validator/schema_helper_methods.rb, line 38 def upper_case(validate, string) return "must contain upper-case letters" if validate && !(/[A-Z]+/ =~ string) end
validate_attribute(attribute)
click to toggle source
# File lib/password_schema_validator/schema_helper_methods.rb, line 66 def validate_attribute(attribute) key, value = attribute if RESERVED_OPTIONS[key.to_sym].nil? raise ArgumentError, invalid_key_error(key) elsif !send(RESERVED_OPTIONS[key.to_sym]).include?(value.class) raise ArgumentError, invalid_value_type(key, RESERVED_OPTIONS[key.to_sym]) end end
validate_schema(options)
click to toggle source
# File lib/password_schema_validator/schema_helper_methods.rb, line 60 def validate_schema(options) options.each do |attribute| validate_attribute(attribute) end end