active_validators 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.rdoc +1 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +56 -0
- data/Rakefile +41 -0
- data/app/validators/date_validator.rb +24 -0
- data/app/validators/time_validator.rb +23 -0
- data/lib/active_validators/engine.rb +5 -0
- data/lib/active_validators/version.rb +3 -0
- data/lib/active_validators.rb +9 -0
- metadata +110 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5436a3651ee6f5e453f1871f3d426d8082d0e491
|
4
|
+
data.tar.gz: c17ab0dd7346ea73c39aafeee99c63f4df608c28
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7364e85dd7197e9fd2a366e18cce38f96e3641bced596e2b7abd8663cba246caa3f290744b3dbfb2ef2361faae820270ffed02edc5b19064c6aed318e6e827f9
|
7
|
+
data.tar.gz: a34c2d2e917c0a261f4fb6eb5a1e4a7610eb1aa7138baa0e7d3fde9ca16dea44f9849426dd13204f79278b4883100a71a9caf39afca7d36f5d342ee668c9302e
|
data/CHANGELOG.rdoc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
= Version changes
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2014 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
= ActiveValidators
|
2
|
+
{<img src="https://badge.fury.io/rb/active_validators.png" alt="Gem Version" />}[http://badge.fury.io/rb/active_validators]
|
3
|
+
{<img src="https://travis-ci.org/nepalez/active_validators.svg" alt="Build Status" />}[https://travis-ci.org/nepalez/active_validators]
|
4
|
+
{<img src="https://codeclimate.com/github/nepalez/active_validators.png" />}[https://codeclimate.com/github/nepalez/active_validators]
|
5
|
+
{<img src="https://gemnasium.com/nepalez/active_validators.svg" alt="Dependency Status" />}[https://gemnasium.com/nepalez/active_validators]
|
6
|
+
{<img src="https://coveralls.io/repos/nepalez/active_validators/badge.png" alt="Coverage Status" />}[https://coveralls.io/r/nepalez/active_validators]
|
7
|
+
|
8
|
+
The plugin provides additional validators for ActiveRecord models.
|
9
|
+
|
10
|
+
=== DateValidator
|
11
|
+
|
12
|
+
Checks the date is after|before|not after|not before another date.
|
13
|
+
|
14
|
+
validates :next_birthday, date: { after: Time.now, not_after: 1.year.from_now }
|
15
|
+
|
16
|
+
Use the <tt>:allow_nil</tt> key to skip validation in case the attribute value isn't set.
|
17
|
+
|
18
|
+
validates :next_birthday, date: { after: Time.now, allow_nil: true }
|
19
|
+
|
20
|
+
Error messages are translated with a corresponding keys (in a same way as in the Rails Guide[http://guides.rubyonrails.org/i18n.html#translations-for-active-record-models]):
|
21
|
+
|
22
|
+
* after_date
|
23
|
+
* before_date
|
24
|
+
* not_after_date
|
25
|
+
* not_before_date
|
26
|
+
|
27
|
+
=== TimeValidator
|
28
|
+
|
29
|
+
Checks the time is after|before|not after|not before given time (in seconds).
|
30
|
+
|
31
|
+
validates :next_alarm, time: { after: Time.now, not_after: 1.day.from_now }
|
32
|
+
|
33
|
+
Use the <tt>:allow_nil</tt> key to skip validation in case the attribute value isn't set.
|
34
|
+
|
35
|
+
validates :next_alarm, time: { after: Time.now, allow_nil: true }
|
36
|
+
|
37
|
+
Error messages are translated with a corresponding keys (in a same way as in the Rails Guide[http://guides.rubyonrails.org/i18n.html#translations-for-active-record-models]):
|
38
|
+
|
39
|
+
* after_time
|
40
|
+
* before_time
|
41
|
+
* not_after_time
|
42
|
+
* not_before_time
|
43
|
+
|
44
|
+
== Installation
|
45
|
+
|
46
|
+
Add string to your Gemfile:
|
47
|
+
|
48
|
+
gem "active_validators"
|
49
|
+
|
50
|
+
== Version changes
|
51
|
+
|
52
|
+
See the CHANGELOG[link:CHANGELOG.rdoc].
|
53
|
+
|
54
|
+
== License
|
55
|
+
|
56
|
+
This project rocks and uses link:MIT-LICENSE.
|
data/Rakefile
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
begin
|
8
|
+
require 'rdoc/task'
|
9
|
+
rescue LoadError
|
10
|
+
require 'rdoc/rdoc'
|
11
|
+
require 'rake/rdoctask'
|
12
|
+
RDoc::Task = Rake::RDocTask
|
13
|
+
end
|
14
|
+
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
17
|
+
rdoc.title = 'ActiveValidators'
|
18
|
+
rdoc.options << '--line-numbers'
|
19
|
+
rdoc.rdoc_files.include('README.rdoc')
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
+
end
|
22
|
+
|
23
|
+
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
24
|
+
load 'rails/tasks/engine.rake'
|
25
|
+
|
26
|
+
Bundler::GemHelper.install_tasks
|
27
|
+
|
28
|
+
require "bundler/gem_tasks"
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
|
31
|
+
RSpec::Core::RakeTask.new(:spec)
|
32
|
+
task :default do
|
33
|
+
sh "bundle exec rake db:migrate RAILS_ENV=test"
|
34
|
+
sh "mkdir spec/dummy/tmp" do |ok, res|
|
35
|
+
nunitSuccessFlag = false
|
36
|
+
end
|
37
|
+
sh "mkdir spec/dummy/tmp/cache" do |ok, res|
|
38
|
+
nunitSuccessFlag = false
|
39
|
+
end
|
40
|
+
sh "bundle exec rspec spec"
|
41
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "active_model"
|
4
|
+
require "active_support/core_ext"
|
5
|
+
|
6
|
+
# Checks the date is after|before|not after|not before another date.
|
7
|
+
#
|
8
|
+
# validates :next_birthday, date: { after: Time.now, not_after: 1.year.from_now }
|
9
|
+
#
|
10
|
+
# Use the <tt>:allow_nil</tt> key to skip validation in case the attribute value isn't set.
|
11
|
+
#
|
12
|
+
# validates :next_birthday, date: { after: Time.now, allow_nil: true }
|
13
|
+
#
|
14
|
+
class DateValidator < ActiveModel::EachValidator
|
15
|
+
def validate_each(record, attribute, value)
|
16
|
+
return if value.nil? && options[:allow_nil]
|
17
|
+
value = value.try(:to_date)
|
18
|
+
{ after: :>, before: :<, not_after: :<=, not_before: :>= }.each do |key, check|
|
19
|
+
if target = options[key].try(:to_date)
|
20
|
+
record.errors.add attribute, :"#{ key }_date" unless value.try check, target
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "active_model"
|
4
|
+
require "active_support/core_ext"
|
5
|
+
|
6
|
+
# Checks the time is after|before|not after|not before given time.
|
7
|
+
#
|
8
|
+
# validates :next_alarm, time: { after: Time.now, not_after: 1.day.from_now }
|
9
|
+
#
|
10
|
+
# Use the <tt>:allow_nil</tt> key to skip validation in case the attribute value isn't set.
|
11
|
+
#
|
12
|
+
# validates :next_alarm, time: { after: Time.now, allow_nil: true }
|
13
|
+
#
|
14
|
+
class TimeValidator < ActiveModel::EachValidator
|
15
|
+
def validate_each(record, attribute, value)
|
16
|
+
return if value.nil? && options[:allow_nil]
|
17
|
+
{ after: :>, before: :<, not_after: :<=, not_before: :>= }.each do |key, check|
|
18
|
+
if target = options[key]
|
19
|
+
record.errors.add attribute, :"#{ key }_time" unless value.try check, target
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: active_validators
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrew Kozin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.0.4
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.0.4
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sqlite3
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.3.9
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.3.9
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec-rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.14.2
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.14.2
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: database_cleaner
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.2.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.2.0
|
69
|
+
description: Contains validators for date and time values.
|
70
|
+
email:
|
71
|
+
- andrew.kozin@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- CHANGELOG.rdoc
|
77
|
+
- MIT-LICENSE
|
78
|
+
- README.rdoc
|
79
|
+
- Rakefile
|
80
|
+
- app/validators/date_validator.rb
|
81
|
+
- app/validators/time_validator.rb
|
82
|
+
- lib/active_validators.rb
|
83
|
+
- lib/active_validators/engine.rb
|
84
|
+
- lib/active_validators/version.rb
|
85
|
+
homepage: https://github.com/nepalez/active_validators
|
86
|
+
licenses:
|
87
|
+
- MIT
|
88
|
+
metadata: {}
|
89
|
+
post_install_message:
|
90
|
+
rdoc_options: []
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - "~>"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '2.1'
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
requirements: []
|
104
|
+
rubyforge_project:
|
105
|
+
rubygems_version: 2.2.2
|
106
|
+
signing_key:
|
107
|
+
specification_version: 4
|
108
|
+
summary: A collection of additional validators for activerecord models.
|
109
|
+
test_files: []
|
110
|
+
has_rdoc:
|