age_validator 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 712afd55e92423f83a8ab1ba23d5aa8a3d8e18ec
4
+ data.tar.gz: 362c24dcf5bf047d01b78af595eeee80c9c407eb
5
+ SHA512:
6
+ metadata.gz: f2ad2f0478f44913c000c6cb6aecd95eeda6e03879fd249581b662367c76a8c6c562269aa675b3253cf0f8a46f0fc44b91875027aec74dbf946ae3427bbc9dad
7
+ data.tar.gz: 8f9b51a7a5cda8b4b6c93bff94744a75e0525a6df5363f6cf4c41f984b9061b6ab843b78ec4e6a094678b58c588d8152b1dbb8478e9dcf8da1f2be1bbaabfd23
File without changes
@@ -0,0 +1,6 @@
1
+ CHANGELOG
2
+ README.md
3
+ Rakefile
4
+ age_validator.gemspec
5
+ lib/age_validator.rb
6
+ Manifest
File without changes
@@ -0,0 +1,16 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+
5
+ Echoe.new('age_validator', '0.1.0') do |p|
6
+ p.summary = "ActiveRecord age validation."
7
+ p.description = "Validate age from a date field in Active Record."
8
+ p.licenses = ['MIT']
9
+ p.url = "https://github.com/rentziass/age_validator.git"
10
+ p.author = "Francesco Renzi"
11
+ p.email = "rentziass@gmail.com"
12
+ p.ignore_pattern = ["tmp/*", "script/*"]
13
+ p.development_dependencies = []
14
+ end
15
+
16
+ Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # stub: age_validator 0.1.0 ruby lib
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "age_validator"
6
+ s.version = "0.1.0"
7
+
8
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
9
+ s.require_paths = ["lib"]
10
+ s.authors = ["Francesco Renzi"]
11
+ s.date = "2015-09-04"
12
+ s.description = "Validate age from a date field in Active Record."
13
+ s.email = "rentziass@gmail.com"
14
+ s.extra_rdoc_files = ["CHANGELOG", "README.md", "lib/age_validator.rb"]
15
+ s.files = ["CHANGELOG", "Manifest", "README.md", "Rakefile", "age_validator.gemspec", "lib/age_validator.rb"]
16
+ s.homepage = "https://github.com/rentziass/age_validator.git"
17
+ s.licenses = ["MIT"]
18
+ s.rdoc_options = ["--line-numbers", "--title", "Age_validator", "--main", "README.md"]
19
+ s.rubyforge_project = "age_validator"
20
+ s.rubygems_version = "2.4.8"
21
+ s.summary = "ActiveRecord age validation."
22
+ end
@@ -0,0 +1,25 @@
1
+ class AgeValidator < ActiveModel::EachValidator
2
+ @@default_options = {}
3
+
4
+ def self.minimum_age(options = {})
5
+ options = default_options.merge(options)
6
+
7
+ options[:minimum] || 18
8
+ end
9
+
10
+ def self.valid?(value, options = {})
11
+ (Date.new(1900)..Time.now.years_ago(minimum_age(options)).to_date).cover? value
12
+ end
13
+
14
+ def self.default_options
15
+ @@default_options
16
+ end
17
+
18
+ def validate_each(record, attribute, value)
19
+ options = @@default_options.merge(self.options)
20
+
21
+ unless self.class.valid?(value, self.options)
22
+ record.errors.add(attribute, options[:message] || :invalid)
23
+ end
24
+ end
25
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: age_validator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Francesco Renzi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-04 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Validate age from a date field in Active Record.
14
+ email: rentziass@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files:
18
+ - CHANGELOG
19
+ - README.md
20
+ - lib/age_validator.rb
21
+ files:
22
+ - CHANGELOG
23
+ - Manifest
24
+ - README.md
25
+ - Rakefile
26
+ - age_validator.gemspec
27
+ - lib/age_validator.rb
28
+ homepage: https://github.com/rentziass/age_validator.git
29
+ licenses:
30
+ - MIT
31
+ metadata: {}
32
+ post_install_message:
33
+ rdoc_options:
34
+ - "--line-numbers"
35
+ - "--title"
36
+ - Age_validator
37
+ - "--main"
38
+ - README.md
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '1.2'
51
+ requirements: []
52
+ rubyforge_project: age_validator
53
+ rubygems_version: 2.4.8
54
+ signing_key:
55
+ specification_version: 4
56
+ summary: ActiveRecord age validation.
57
+ test_files: []