validates_website 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/validates_website.rb +30 -0
- data/rails/init.rb +1 -0
- metadata +49 -0
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
require 'resolv'
|
3
|
+
|
4
|
+
module Rubykitchen
|
5
|
+
module ValidatesWebsite
|
6
|
+
module Validator
|
7
|
+
class WebsiteValidator < ActiveModel::EachValidator
|
8
|
+
def validate_each(record, attribute, value)
|
9
|
+
if system("ping -c 1 google.com") then
|
10
|
+
ip = Resolv.getaddress value rescue []
|
11
|
+
if ip.nil? then
|
12
|
+
record.errors[attribute] << "Its not an active site as no IP is mapped to it."
|
13
|
+
end
|
14
|
+
else
|
15
|
+
record.errors[attribute] << "No active internet connection to check if valid ip exist for website url"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
module ClassMethods
|
22
|
+
def validates_website_of(*attr_names)
|
23
|
+
validates_with ActiveRecord::Base::WebsiteValidator, _merge_attributes(attr_names)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
ActiveRecord::Base.send(:include, Rubykitchen::ValidatesWebsite::Validator)
|
30
|
+
ActiveRecord::Base.send(:extend, Rubykitchen::ValidatesWebsite::ClassMethods)
|
data/rails/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'validates_website'
|
metadata
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: validates_website
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Harisankar P S
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-03-19 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: A Validator to validate if the website's url is being submited is an
|
15
|
+
active one or spam
|
16
|
+
email:
|
17
|
+
- mailme@hsps.in
|
18
|
+
executables: []
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- lib/validates_website.rb
|
23
|
+
- rails/init.rb
|
24
|
+
homepage: http://tech.hsps.in
|
25
|
+
licenses: []
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ! '>='
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ! '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
requirements: []
|
43
|
+
rubyforge_project:
|
44
|
+
rubygems_version: 1.8.23
|
45
|
+
signing_key:
|
46
|
+
specification_version: 3
|
47
|
+
summary: A Validator to check if the website submited is active
|
48
|
+
test_files: []
|
49
|
+
has_rdoc:
|