Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/glacials/splits-io. a speedrunning data store and analysis engine splits.io
Something went wrong. Try again.
12345678910111213141516171819202122232425262728class RunValidator < ActiveModel::Validator def validate(record) validate_default_timing(record) validate_video_url(record) end
private
def validate_default_timing(record) if !['real', 'game'].include?(record.default_timing) record.errors[:base] << 'Default timing must be either "real" or "game".' end end
def validate_video_url(record) record.video_url = nil if record.video_url.try(:strip) == '' return if record.video_url.nil?
URI.parse(record.video_url).tap do |uri| unless uri.host =~ /^(www\.)?(twitch\.tv|youtube\.com|youtu\.be)$/ record.errors[:base] << 'Your video URL must be a link to a Twitch or YouTube video.' end end rescue URI::InvalidURIError record.errors[:base] << 'Your video URL must be a link to a Twitch or YouTube video.' endend