Class: Rubykitchen::ValidatesWebsite::Validator::WebsiteValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/validates_website.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/validates_website.rb', line 8

def validate_each(record, attribute, value)
  if system("ping -c 1 google.com") then
    ip = Resolv.getaddress value rescue []
    if ip.nil? then
      record.errors[attribute] << "Its not an active site as no IP is mapped to it."
    end
  else
    record.errors[attribute] << "No active internet connection to check if valid ip exist for website url"
  end
end