validates_age 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/validates_age.rb +28 -0
- data/rails/init.rb +1 -0
- metadata +48 -0
@@ -0,0 +1,28 @@
|
|
1
|
+
require "active_record"
|
2
|
+
|
3
|
+
module Rubykitchen
|
4
|
+
module ValidatesAge
|
5
|
+
module Validator
|
6
|
+
class AgeValidator < ActiveModel::EachValidator
|
7
|
+
def validate_each(record, attribute, value)
|
8
|
+
if value > Date.today
|
9
|
+
record.errors[attribute] << "As per the DOB you are Not yet Born"
|
10
|
+
elsif ((Date.today - value) < 13)
|
11
|
+
record.errors[attribute] << "Your age is less than 13"
|
12
|
+
elsif ((Date.today - value) > 120)
|
13
|
+
record.errors[attribute] << "Your age is older than the oldrst Human Being"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
module ClassMethods
|
20
|
+
def validates_age_of(*attr_names)
|
21
|
+
validates_with ActiveRecord::Base::AgeValidator, _merge_attributes(attr_names)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
ActiveRecord::Base.send(:include, Rubykitchen::ValidatesAge::Validator)
|
28
|
+
ActiveRecord::Base.send(:extend, Rubykitchen::ValidatesAge::ClassMethods)
|
data/rails/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'validates_age'
|
metadata
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: validates_age
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Harisankar P S
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-03-08 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: A Validator to validate the age of a person, useful during signup
|
15
|
+
email:
|
16
|
+
- mailme@hsps.in
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- lib/validates_age.rb
|
22
|
+
- rails/init.rb
|
23
|
+
homepage: http://rubygems.org/gems/hola
|
24
|
+
licenses: []
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ! '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
requirements: []
|
42
|
+
rubyforge_project:
|
43
|
+
rubygems_version: 1.8.23
|
44
|
+
signing_key:
|
45
|
+
specification_version: 3
|
46
|
+
summary: A Validator to validate DOB
|
47
|
+
test_files: []
|
48
|
+
has_rdoc:
|