class ActiveModel::Validations::TwitterValidator
Constants
- TWITTER_ATSIGN_REGEXP
Regexp to test using twitter username as @sign.
- TWITTER_NOATSIGN_REGEXP
Regexp to test against usernames without the @sign
- TWITTER_URL_REGEXP
Regexp used to detect twitter username within the URL.
- TWITTER_USERNAME_REGEXP
Basic username regexp
Public Instance Methods
validate_each(record, attribute, value)
click to toggle source
# File lib/active_validators/active_model/validations/twitter_validator.rb, line 18 def validate_each(record, attribute, value) format = options[:format].to_sym if options[:format] if value.nil? record.errors.add(attribute, :blank) elsif format == :url match = value.match(TWITTER_URL_REGEXP) record.errors.add(attribute) unless match && !match[1].nil? elsif format == :username_with_at record.errors.add(attribute) unless value =~ TWITTER_ATSIGN_REGEXP else record.errors.add(attribute) unless value =~ TWITTER_NOATSIGN_REGEXP end end