ae-validates_timeliness 4.0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: edab8c036ee66f864edcb09a7615c1969d73e65b
4
+ data.tar.gz: b7db9f4ef6dab5825f54a1260c2750a74b9044ae
5
+ SHA512:
6
+ metadata.gz: c81dc3f1ff8a6d64e5fa732dc5e60d9b4ef7300135c8c214d7525804c91fae3b7d1954616c076880cccde1d929b16caa90793faec296a5a6d647dd364844b3bc
7
+ data.tar.gz: 6b7dd28e9b84d78c8b6fe8713bef26edd014cad758d338a4c093d2357a595bd554fdc364bae1e0edb2673e4c8b982095fa9d5f2b2f9533ba3761a6b6a6220215
@@ -0,0 +1,11 @@
1
+ appraise "rails_4_0" do
2
+ gem "rails", "~> 4.0.0"
3
+ end
4
+
5
+ appraise "rails_4_1" do
6
+ gem "rails", "~> 4.1.0"
7
+ end
8
+
9
+ appraise "rails_4_2" do
10
+ gem "rails", "~> 4.2.0"
11
+ end
@@ -0,0 +1,190 @@
1
+ = 4.0.0 [2015-07-19]
2
+ * Better compatibility with Rails 4.x (and drop support < 4.0)
3
+ * Support Ruby 2.0+
4
+ * Drop Mongoid support (PRs welcome to restore this)
5
+ * Drop Extensions (PRs welcome to restore this)
6
+ * Distribute gem as ae-validate_timeliness
7
+
8
+ = 3.0.14 [2012-08-23]
9
+ * Fix for using validates :timeliness => {} form to correctly add attributes to timeliness validated attributes.
10
+
11
+ = 3.0.13 [2012-08-21]
12
+ * Fix ActiveRecord issues with using plugin parser by using old way of caching values.
13
+ * Allow any ActiveRecord non-column attribute to be validated
14
+
15
+ = 3.0.12 [2012-06-23]
16
+ * Fix load order issue when relying on Railtie to load ActiveRecord extension
17
+
18
+ = 3.0.11 [2012-04-01]
19
+ * Change dependency on Timeliness version due to a broken release
20
+
21
+ = 3.0.10 [2012-03-26]
22
+ * Fix for ActiveRecord shim and validation with :allow_blank => true in AR 3.1+. Fixes issue#52.
23
+
24
+ = 3.0.9 [2012-03-26]
25
+ * ActiveRecord 3.1+ suport
26
+ * Fixes for multiparameter extension with empty date values (thanks @mogox, @Sharagoz)
27
+
28
+ = 3.0.8 [2011-12-24]
29
+ * Remove deprecated InstanceMethods module when using AS::Concern (carlosantoniodasilva)
30
+ * Update Mongoid shim for v2.3 compatability.
31
+
32
+ = 3.0.7 [2011-09-21]
33
+ * Fix ActiveRecord before_type_cast extension for non-dirty attributes.
34
+ * Don't override AR before_type_cast for >= 3.1.0 which now has it's own implementation for date/time attributes.
35
+ * Fix DateTimeSelect extension to convert params to integers (#45)
36
+ * Add #change method to DateTimeSelect extension (@trusche, #45)
37
+ * Cleanup Mongoid shim.
38
+
39
+ = 3.0.6 [2011-05-09]
40
+ * Fix for AR type conversion for date columns when using plugin parser.
41
+ * Add timeliness_type_cast_code for ORM specific type casting after parsing.
42
+
43
+ = 3.0.5 [2011-01-29]
44
+ * Fix for Conversion#parse when given nil value (closes issue #34)
45
+
46
+ = 3.0.4 [2011-01-22]
47
+ * Fix :between option which was being ignored (ebeigarts)
48
+ * Use class_attribute to remove deprecated class_inheritable_accessor
49
+ * Namespace copied validator class to ActiveModel::Validations::Timeliness for :timeliness option
50
+
51
+ = 3.0.3 [2010-12-11]
52
+ * Fix validation of values which don't respond to to_date or to_time (renatoelias)
53
+
54
+ = 3.0.2 [2010-12-04]
55
+ * Fix AR multiparameter extension for Date columns
56
+ * Update to Timeliness 0.3.2 for zone abbreviation and offset support
57
+
58
+ = 3.0.1 [2010-11-02]
59
+ * Generate timeliness write methods in an included module to allow overriding in model class (josevalim)
60
+
61
+ = 3.0.0 [2010-10-18]
62
+ * Rails 3 and ActiveModel compatibility
63
+ * Uses ActiveModel::EachValidator as validator base class.
64
+ * Configuration settings stored in ValidatesTimeliness module only. ValidatesTimeliness.setup block to configure.
65
+ * Parser extracted to the Timeliness gem http://github.com/adzap/timeliness
66
+ * Parser is disabled by default. See initializer for enabling it.
67
+ * Removed RSpec matcher. Encouraged poor specs by copy-pasting from spec to model, or worse, the other way round.
68
+ * Method override for parsing and before type cast values is on validated attributes only. Old version handled all date/datetime columns, validates or not. Too intrusive.
69
+ * Add validation helpers to classes using extend_orms config setting. e.g. conf.extend_orms = [ :active_record ]
70
+ * Changed :between option so it is split into :on_or_after and :on_or_before option values. The error message for either failing check will be used instead of a between error message.
71
+ * Provides :timeliness option key for validates class method. Be sure to pass :type option as well e.g. :type => :date.
72
+ * Allows validation methods to be called on record instances as per ActiveModel API.
73
+ * Performs parsing (optional) and raw value caching (before_type_cast) on validated attributes only. It used to be all date, time and datetime attributes.
74
+
75
+ = 2.3.1 [2010-03-19]
76
+ * Fixed bug where custom attribute writer method for date/times were being overriden
77
+
78
+ = 2.3.0 [2010-02-04]
79
+ * Backwards incompatible change to :equal_to option. Fixed error message clash with :equal_to option which exists in Rails already. Option is now :is_at.
80
+ * Fixed I18n support so it returns missing translation message instead of error
81
+ * Fixed attribute method bug. Write method was bypassed when method was first generated and used Rails default parser.
82
+ * Fixed date/time selects when using enable_datetime_select_extension! when some values empty
83
+ * Fixed ISO8601 datetime format which is now split into two formats
84
+ * Changed I18n error value format to fallback to global default if missing in locale
85
+ * Refactored date/time select invalid value extension to use param values. Functionality will be extracted from plugin for v3.
86
+
87
+ = 2.2.2 [2009-09-19]
88
+ * Fixed dummy_time using make_time to respect timezone. Fixes 1.9.1 bug.
89
+
90
+ = 2.2.1 [2009-09-12]
91
+ * Fixed dummy date part for time types in Validator.type_cast_value
92
+ * No more core extensions! Removed dummy_time methods.
93
+
94
+ = 2.2.0 [2009-09-12]
95
+ * Ruby 1.9 support!
96
+ * Customise dummy date values for time types. See DUMMY DATE FOR TIME TYPES.
97
+ * Fixed matcher conflict with Shoulda. Load plugin matcher manually now see matcher section in README
98
+ * Fixed :ignore_usec when used with :with_time or :with_date
99
+ * Some clean up and refactoring
100
+
101
+ = 2.1.0 [2009-06-20]
102
+ * Added ambiguous year threshold setting in Formats class to customize the threshold for 2 digit years (See README)
103
+ * Fixed interpolation values in custom error message for Rails 2.2+
104
+ * Fixed custom I18n local override of en locale
105
+ * Dramatically simplified ActiveRecord monkey patching and hackery
106
+
107
+ = 2.0.0 [2009-04-12]
108
+ * Error value formats are now specified in the i18n locale file instead of updating plugin hash. See OTHER CUSTOMISATION section in README.
109
+ * Date/time select helper extension is disabled by default. To enable see DISPLAY INVALID VALUES IN DATE HELPERS section in README to enable.
110
+ * Added :format option to limit validation to a single format if desired
111
+ * Matcher now supports :equal_to option
112
+ * Formats.parse can take :include_offset option to include offset value from string in seconds, if string contains an offset. Offset not used in rest of plugin yet.
113
+ * Refactored to remove as much plugin code from ActiveRecord as possible.
114
+
115
+ = 1.1.7 [2009-03-26]
116
+ * Minor change to multiparameter attributes which I had not properly implemented for chaining
117
+
118
+ = 1.1.6 [2009-03-19]
119
+ * Rail 2.3 support
120
+ * Added :with_date and :with_time options. They allow an attribute to be combined with another attribute or value to make a datetime value for validation against the temporal restrictions
121
+ * Added :equal_to option
122
+ * Option key validation
123
+ * Better behaviour with other plugins using alias_method_chain on read_attribute and define_attribute_methods
124
+ * Added option to enable datetime_select extension for future use to optionally enable. Enabled by default until version 2.
125
+ * Added :ignore_usec option for datetime restrictions to be compared without microsecond
126
+ * some refactoring
127
+
128
+ = 1.1.5 [2009-01-21]
129
+ * Fixed regex for 'yy' format token which wasn't greedy enough for date formats ending with year when a datetime string parsed as date with a 4 digit year
130
+
131
+ = 1.1.4 [2009-01-13]
132
+ * Make months names respect i18n in Formats
133
+
134
+ = 1.1.3 [2009-01-13]
135
+ * Fixed bug where time and date attributes still being parsed on read using Rails default parser [reported by Brad (pvjq)]
136
+
137
+ = 1.1.2 [2009-01-12]
138
+ * Fixed bugs
139
+ * matcher failing for custom error message without interpolation keys using I18n
140
+ * validator custom error messages not being extracted
141
+
142
+ = 1.1.1 [2009-01-03]
143
+ * Fixed bug in matcher for options local variable
144
+
145
+ = 1.1.0 [2009-01-01]
146
+ * Added between option
147
+
148
+ = 1.0.0 [2008-12-06]
149
+ * Gemified!
150
+ * Refactor of plugin into a Data Mapper style validator class which makes for a cleaner implementation and possible future Merb\Data Mapper support
151
+ * Added Rails 2.2 i18n support. Plugin error messages can specified in locale files. See README.
152
+ * ignore_datetime_restriction_errors setting has been moved from AR to ValidatesTimeliness::Validator.ignore_restriction_errors
153
+ * date_time_error_value_formats setting has been moved from AR to ValidatesTimeliness::Validator.error_value_formats
154
+ * Namespaced modules and specs
155
+ * Clean up of specs
156
+ * fixed a few bugs
157
+ * accessor methods not generating properly due method name stored as symbol in generated_attributes which fails on lookup
158
+ * force value assigned to time/datetime attributes to time objects
159
+
160
+ = 0.1.0 [2008-12-06]
161
+ * Tagged plugin as version 0.1.0
162
+
163
+ = 2008-11-13
164
+ * allow uppercase meridian to be valid [reported by Alex (http://alex.digns.com/)]
165
+
166
+ = 2008-10-28
167
+ * fixed bug when dirty attributes not reflecting change when attribute changed from time value to nil [reported by Brad (pvjq)]
168
+ * fixes for Rails 2.2 compatibility. Will refactor in to Rails version specific branches in the future.
169
+
170
+ = 2008-09-24
171
+ * refactored attribute write method definitions
172
+
173
+ = 2008-08-25
174
+ * fixed bug for non-timezone write method not updating changed attributes hash [reported by Sylvestre Mergulhão]
175
+
176
+ = 2008-08-22
177
+ * fixed bug with attribute cache not clearing on write for date and time columns [reported by Sylvestre Mergulhão]
178
+ * parse method returns Date object for date column assigned string as per normal Rails behaviour
179
+ * parse method returns same object type when assigned Date or Time object as per normal Rails behaviour
180
+
181
+ = 2008-08-07
182
+ * modified matcher option value parsing to allow same value types as validation method
183
+ * fixed matcher message
184
+
185
+ = 2008-08-02
186
+ * refactored validation
187
+ * refactored matcher
188
+
189
+ = 2008-07-30
190
+ * removed setting values to nil when validation fails to preserve before_type_cast value
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'rails', '~> 4.2.0'
6
+ gem 'timecop'
7
+ gem 'appraisal'
8
+ gem 'sqlite3'
9
+ gem 'nokogiri'
10
+
11
+ group :active_record do
12
+ gem 'sqlite3-ruby', :require => 'sqlite3'
13
+ end
@@ -0,0 +1,178 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ae-validates_timeliness (4.0.0)
5
+ rails (~> 4.0)
6
+ timeliness (~> 0.3.7)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ actionmailer (4.2.3)
12
+ actionpack (= 4.2.3)
13
+ actionview (= 4.2.3)
14
+ activejob (= 4.2.3)
15
+ mail (~> 2.5, >= 2.5.4)
16
+ rails-dom-testing (~> 1.0, >= 1.0.5)
17
+ actionpack (4.2.3)
18
+ actionview (= 4.2.3)
19
+ activesupport (= 4.2.3)
20
+ rack (~> 1.6)
21
+ rack-test (~> 0.6.2)
22
+ rails-dom-testing (~> 1.0, >= 1.0.5)
23
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
24
+ actionview (4.2.3)
25
+ activesupport (= 4.2.3)
26
+ builder (~> 3.1)
27
+ erubis (~> 2.7.0)
28
+ rails-dom-testing (~> 1.0, >= 1.0.5)
29
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
30
+ activejob (4.2.3)
31
+ activesupport (= 4.2.3)
32
+ globalid (>= 0.3.0)
33
+ activemodel (4.2.3)
34
+ activesupport (= 4.2.3)
35
+ builder (~> 3.1)
36
+ activerecord (4.2.3)
37
+ activemodel (= 4.2.3)
38
+ activesupport (= 4.2.3)
39
+ arel (~> 6.0)
40
+ activesupport (4.2.3)
41
+ i18n (~> 0.7)
42
+ json (~> 1.7, >= 1.7.7)
43
+ minitest (~> 5.1)
44
+ thread_safe (~> 0.3, >= 0.3.4)
45
+ tzinfo (~> 1.1)
46
+ appraisal (2.0.2)
47
+ bundler
48
+ rake
49
+ thor (>= 0.14.0)
50
+ arel (6.0.2)
51
+ builder (3.2.2)
52
+ coveralls (0.8.2)
53
+ json (~> 1.8)
54
+ rest-client (>= 1.6.8, < 2)
55
+ simplecov (~> 0.10.0)
56
+ term-ansicolor (~> 1.3)
57
+ thor (~> 0.19.1)
58
+ diff-lcs (1.2.5)
59
+ docile (1.1.5)
60
+ domain_name (0.5.24)
61
+ unf (>= 0.0.5, < 1.0.0)
62
+ erubis (2.7.0)
63
+ globalid (0.3.5)
64
+ activesupport (>= 4.1.0)
65
+ http-cookie (1.0.2)
66
+ domain_name (~> 0.5)
67
+ i18n (0.7.0)
68
+ json (1.8.3)
69
+ loofah (2.0.2)
70
+ nokogiri (>= 1.5.9)
71
+ mail (2.6.3)
72
+ mime-types (>= 1.16, < 3)
73
+ mime-types (2.6.1)
74
+ mini_portile (0.6.2)
75
+ minitest (5.7.0)
76
+ netrc (0.10.3)
77
+ nokogiri (1.6.6.2)
78
+ mini_portile (~> 0.6.0)
79
+ rack (1.6.4)
80
+ rack-test (0.6.3)
81
+ rack (>= 1.0)
82
+ rails (4.2.3)
83
+ actionmailer (= 4.2.3)
84
+ actionpack (= 4.2.3)
85
+ actionview (= 4.2.3)
86
+ activejob (= 4.2.3)
87
+ activemodel (= 4.2.3)
88
+ activerecord (= 4.2.3)
89
+ activesupport (= 4.2.3)
90
+ bundler (>= 1.3.0, < 2.0)
91
+ railties (= 4.2.3)
92
+ sprockets-rails
93
+ rails-deprecated_sanitizer (1.0.3)
94
+ activesupport (>= 4.2.0.alpha)
95
+ rails-dom-testing (1.0.6)
96
+ activesupport (>= 4.2.0.beta, < 5.0)
97
+ nokogiri (~> 1.6.0)
98
+ rails-deprecated_sanitizer (>= 1.0.1)
99
+ rails-html-sanitizer (1.0.2)
100
+ loofah (~> 2.0)
101
+ railties (4.2.3)
102
+ actionpack (= 4.2.3)
103
+ activesupport (= 4.2.3)
104
+ rake (>= 0.8.7)
105
+ thor (>= 0.18.1, < 2.0)
106
+ rake (10.4.2)
107
+ rest-client (1.8.0)
108
+ http-cookie (>= 1.0.2, < 2.0)
109
+ mime-types (>= 1.16, < 3.0)
110
+ netrc (~> 0.7)
111
+ rspec (3.3.0)
112
+ rspec-core (~> 3.3.0)
113
+ rspec-expectations (~> 3.3.0)
114
+ rspec-mocks (~> 3.3.0)
115
+ rspec-collection_matchers (1.1.2)
116
+ rspec-expectations (>= 2.99.0.beta1)
117
+ rspec-core (3.3.2)
118
+ rspec-support (~> 3.3.0)
119
+ rspec-expectations (3.3.1)
120
+ diff-lcs (>= 1.2.0, < 2.0)
121
+ rspec-support (~> 3.3.0)
122
+ rspec-mocks (3.3.2)
123
+ diff-lcs (>= 1.2.0, < 2.0)
124
+ rspec-support (~> 3.3.0)
125
+ rspec-rails (3.3.3)
126
+ actionpack (>= 3.0, < 4.3)
127
+ activesupport (>= 3.0, < 4.3)
128
+ railties (>= 3.0, < 4.3)
129
+ rspec-core (~> 3.3.0)
130
+ rspec-expectations (~> 3.3.0)
131
+ rspec-mocks (~> 3.3.0)
132
+ rspec-support (~> 3.3.0)
133
+ rspec-support (3.3.0)
134
+ simplecov (0.10.0)
135
+ docile (~> 1.1.0)
136
+ json (~> 1.8)
137
+ simplecov-html (~> 0.10.0)
138
+ simplecov-html (0.10.0)
139
+ sprockets (3.2.0)
140
+ rack (~> 1.0)
141
+ sprockets-rails (2.3.2)
142
+ actionpack (>= 3.0)
143
+ activesupport (>= 3.0)
144
+ sprockets (>= 2.8, < 4.0)
145
+ sqlite3 (1.3.10)
146
+ sqlite3-ruby (1.3.3)
147
+ sqlite3 (>= 1.3.3)
148
+ term-ansicolor (1.3.2)
149
+ tins (~> 1.0)
150
+ thor (0.19.1)
151
+ thread_safe (0.3.5)
152
+ timecop (0.7.4)
153
+ timeliness (0.3.7)
154
+ tins (1.5.4)
155
+ tzinfo (1.2.2)
156
+ thread_safe (~> 0.1)
157
+ unf (0.1.4)
158
+ unf_ext
159
+ unf_ext (0.0.7.1)
160
+
161
+ PLATFORMS
162
+ ruby
163
+
164
+ DEPENDENCIES
165
+ ae-validates_timeliness!
166
+ appraisal
167
+ coveralls
168
+ nokogiri
169
+ rails (~> 4.2.0)
170
+ rspec (~> 3.0)
171
+ rspec-collection_matchers
172
+ rspec-rails (~> 3.0)
173
+ sqlite3
174
+ sqlite3-ruby
175
+ timecop
176
+
177
+ BUNDLED WITH
178
+ 1.10.5
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008-2010 Adam Meehan
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.
@@ -0,0 +1,329 @@
1
+ # ValidatesTimeliness
2
+ [![Gem Version][gem-badge]][gem]
3
+ [![Build status][build-badge]][build]
4
+ [![Coverage Status][coverage-badge]][coverage]
5
+
6
+ ## Description
7
+
8
+ Complete validation of dates, times and datetimes for Rails 4.x.
9
+
10
+ This is a fork of [original validates_timeliness gem][original] by [Adam Meehan][adzap]
11
+ with patches from [John Carney](https://github.com/johncarney/validates_timeliness) and [StatProSA](https://github.com/StatProSA/sp-validates_timeliness). I've added
12
+ additional compatibility with various Rails 4.x version as well as STI and performance
13
+ fixes.
14
+
15
+ ## Features
16
+
17
+ * Adds validation for dates, times and datetimes to ActiveModel
18
+ * Handles timezones and type casting of values for you
19
+ * Only Rails date/time validation plugin offering complete validation (See
20
+ ORM/ODM support)
21
+ * Uses extensible date/time parser (Using
22
+ [timeliness gem][timeliness]. See Plugin Parser)
23
+ * Supports I18n for the error messages
24
+ * Supports Ruby 2.0+
25
+
26
+ ## Installation
27
+
28
+ # in Gemfile
29
+ gem 'ae-validates_timeliness'
30
+
31
+ # Run bundler
32
+ $ bundle install
33
+
34
+ Then run
35
+
36
+ $ rails generate validates_timeliness:install
37
+
38
+ This creates configuration initializer and locale files. In the initializer,
39
+ there are a number of config options to customize the plugin.
40
+
41
+ NOTE: You may wish to enable the plugin parser and the extensions to start.
42
+ Please read those sections first.
43
+
44
+ ## Examples
45
+
46
+ validates_datetime :occurred_at
47
+
48
+ validates_date :date_of_birth, :before => lambda { 18.years.ago },
49
+ :before_message => "must be at least 18 years old"
50
+
51
+ validates_datetime :finish_time, :after => :start_time # Method symbol
52
+
53
+ validates_date :booked_at, :on => :create, :on_or_after => :today # See Restriction Shorthand.
54
+
55
+ validates_time :booked_at, :between => ['9:00am', '5:00pm'] # On or after 9:00AM and on or before 5:00PM
56
+ validates_time :booked_at, :between => '9:00am'..'5:00pm' # The same as previous example
57
+ validates_time :booked_at, :between => '9:00am'...'5:00pm' # On or after 9:00AM and strictly before 5:00PM
58
+
59
+ validates_time :breakfast_time, :on_or_after => '6:00am',
60
+ :on_or_after_message => 'must be after opening time',
61
+ :before => :lunchtime,
62
+ :before_message => 'must be before lunch time'
63
+
64
+ ## Usage
65
+
66
+ To validate a model with a date, time or datetime attribute you just use the
67
+ validation method
68
+
69
+ class Person < ActiveRecord::Base
70
+ validates_date :date_of_birth, :on_or_before => lambda { Date.current }
71
+ # or
72
+ validates :date_of_birth, :timeliness => {:on_or_before => lambda { Date.current }, :type => :date}
73
+ end
74
+
75
+ or even on a specific record, per ActiveModel API.
76
+
77
+ @person.validates_date :date_of_birth, :on_or_before => lambda { Date.current }
78
+
79
+ The list of validation methods available are as follows:
80
+
81
+ validates_date - validate value as date
82
+ validates_time - validate value as time only i.e. '12:20pm'
83
+ validates_datetime - validate value as a full date and time
84
+ validates - use the :timeliness key and set the type in the hash.
85
+
86
+ The validation methods take the usual options plus some specific ones to
87
+ restrict the valid range of dates or times allowed
88
+
89
+ Temporal options (or restrictions):
90
+
91
+ :is_at - Attribute must be equal to value to be valid
92
+ :before - Attribute must be before this value to be valid
93
+ :on_or_before - Attribute must be equal to or before this value to be valid
94
+ :after - Attribute must be after this value to be valid
95
+ :on_or_after - Attribute must be equal to or after this value to be valid
96
+ :between - Attribute must be between the values to be valid. Range or Array of 2 values.
97
+
98
+ Regular validation options:
99
+
100
+ :allow_nil - Allow a nil value to be valid
101
+ :allow_blank - Allows a nil or empty string value to be valid
102
+ :if - Execute validation when :if evaluates true
103
+ :unless - Execute validation when :unless evaluates false
104
+ :on - Specify validation context e.g :save, :create or :update. Default is :save.
105
+
106
+ Special options:
107
+
108
+ :ignore_usec - Ignores microsecond value on datetime restrictions
109
+ :format - Limit validation to a single format for special cases. Requires plugin parser.
110
+
111
+ The temporal restrictions can take 4 different value types:
112
+
113
+ * Date, Time, or DateTime object value
114
+ * Proc or lambda object which may take an optional parameter, being the record
115
+ object
116
+ * A symbol matching a method name in the model
117
+ * String value
118
+
119
+ When an attribute value is compared to temporal restrictions, they are
120
+ compared as the same type as the validation method type. So using
121
+ validates_date means all values are compared as dates.
122
+
123
+ ## Configuration
124
+
125
+ ### ORM/ODM Support
126
+
127
+ **Note** Mongoid does not work in ae-validates\_timeliness. The code /
128
+ spec are still there and I'm happy to accept PRs that restore this
129
+ functionality.
130
+
131
+ The plugin adds date/time validation to ActiveModel for any ORM/ODM that
132
+ supports the ActiveModel validations component. However, there is an issue
133
+ with most ORM/ODMs which does not allow 100% date/time validation by default.
134
+ Specifically, when you assign an invalid date/time value to an attribute, most
135
+ ORM/ODMs will only store a nil value for the attribute. This causes an issue
136
+ for date/time validation, since we need to know that a value was assigned but
137
+ was invalid. To fix this, we need to cache the original invalid value to know
138
+ that the attribute is not just nil.
139
+
140
+ Each ORM/ODM requires a specific shim to fix it. The plugin includes a shim
141
+ for ActiveRecord. You can activate them like so
142
+
143
+ ValidatesTimeliness.setup do |config|
144
+
145
+ # Extend ORM/ODMs for full support (:active_record).
146
+ config.extend_orms = [ :active_record ]
147
+
148
+ end
149
+
150
+ By default the plugin extends ActiveRecord if loaded. If you wish to extend
151
+ another ORM then look at the [wiki page][orm-support] for more information.
152
+
153
+ It is not required that you use a shim, but you will not catch errors when the
154
+ attribute value is invalid and evaluated to nil.
155
+
156
+ ### Error Messages
157
+
158
+ Using the I18n system to define new defaults:
159
+
160
+ en:
161
+ errors:
162
+ messages:
163
+ invalid_date: "is not a valid date"
164
+ invalid_time: "is not a valid time"
165
+ invalid_datetime: "is not a valid datetime"
166
+ is_at: "must be at %{restriction}"
167
+ before: "must be before %{restriction}"
168
+ on_or_before: "must be on or before %{restriction}"
169
+ after: "must be after %{restriction}"
170
+ on_or_after: "must be on or after %{restriction}"
171
+
172
+ The `%{restriction}` signifies where the interpolation value for the
173
+ restriction will be inserted.
174
+
175
+ You can also use validation options for custom error messages. The following
176
+ option keys are available:
177
+
178
+ :invalid_date_message
179
+ :invalid_time_message
180
+ :invalid_datetime_message
181
+ :is_at_message
182
+ :before_message
183
+ :on_or_before_message
184
+ :after_message
185
+ :on_or_after_message
186
+
187
+ Note: There is no :between_message option. The between error message should be
188
+ defined using the :on_or_after and :on_or_before (:before in case when
189
+ :between argument is a Range with excluded high value, see Examples) messages.
190
+
191
+ It is highly recommended you use the I18n system for error messages.
192
+
193
+ ### Plugin Parser
194
+
195
+ The plugin uses the [timeliness gem][timeliness] as a fast, configurable and
196
+ extensible date and time parser. You can add or remove valid formats for
197
+ dates, times, and datetimes. It is also more strict than the Ruby parser,
198
+ which means it won't accept day of the month if it's not a valid number for
199
+ the month.
200
+
201
+ By default the parser is disabled. To enable it:
202
+
203
+ # in the setup block
204
+ config.use_plugin_parser = true
205
+
206
+ Enabling the parser will mean that strings assigned to attributes validated
207
+ with the plugin will be parsed using the gem. See the [wiki][plugin-parser]
208
+ for more details about the parser configuration.
209
+
210
+
211
+ ### Restriction Shorthand
212
+
213
+ It is common to restrict an attribute to being on or before the current time
214
+ or current day. To specify this you need to use a lambda as an option value
215
+ e.g. `lambda { Time.current }. This can be tedious noise amongst your
216
+ validations for something so common. To combat this the plugin allows you to
217
+ use shorthand symbols for often used relative times or dates.
218
+
219
+ Just provide the symbol as the option value like so:
220
+
221
+ validates_date :birth_date, :on_or_before => :today
222
+
223
+ The :today symbol is evaluated as `lambda { Date.today }`. The :now and :today
224
+ symbols are pre-configured. Configure your own like so:
225
+
226
+ # in the setup block
227
+ config.restriction_shorthand_symbols.update(
228
+ :yesterday => lambda { 1.day.ago }
229
+ )
230
+
231
+ ### Default Timezone
232
+
233
+ The plugin needs to know the default timezone you are using when parsing or
234
+ type casting values. If you are using ActiveRecord then the default is
235
+ automatically set to the same default zone as ActiveRecord. If you are using
236
+ another ORM you may need to change this setting.
237
+
238
+ # in the setup block
239
+ config.default_timezone = :utc
240
+
241
+ By default it will be UTC if ActiveRecord is not loaded.
242
+
243
+ ### Dummy Date For Time Types
244
+
245
+ Given that Ruby has no support for a time-only type, all time type columns are
246
+ evaluated as a regular Time class objects with a dummy date value set. Rails
247
+ defines the dummy date as 2000-01-01. So a time of '12:30' is evaluated as a
248
+ Time value of '2000-01-01 12:30'. If you need to customize this for some
249
+ reason you can do so as follows
250
+
251
+ # in the setup block
252
+ config.dummy_date_for_time_type = [2009, 1, 1]
253
+
254
+ The value should be an array of 3 values being year, month and day in that
255
+ order.
256
+
257
+ ### Temporal Restriction Errors
258
+
259
+ When using the validation temporal restrictions there are times when the
260
+ restriction option value itself may be invalid. This will add an error to the
261
+ model such as 'Error occurred validating birth_date for :before restriction'.
262
+ These can be annoying in development or production as you most likely just
263
+ want to skip the option if no valid value was returned. By default these
264
+ errors are displayed in Rails test mode.
265
+
266
+ To turn them on/off:
267
+
268
+ # in the setup block
269
+ config.ignore_restriction_errors = true
270
+
271
+ ## Extensions
272
+
273
+ **NOTE** These extensions do not work in ae-validates\_timeliness. The code /
274
+ spec are still there and I'm happy to accept PRs that restore this
275
+ functionality.
276
+
277
+ ### Strict Parsing for Select Helpers
278
+
279
+ When using date/time select helpers, the component values are handled by
280
+ ActiveRecord using the Time class to instantiate them into a time value. This
281
+ means that some invalid dates, such as 31st June, are shifted forward and
282
+ treated as valid. To handle these cases in a strict way, you can enable the
283
+ plugin extension to treat them as invalid dates.
284
+
285
+ To activate it, uncomment this line in the initializer:
286
+
287
+ # in the setup block
288
+ config.enable_multiparameter_extension!
289
+
290
+ ### Display Invalid Values in Select Helpers
291
+
292
+ The plugin offers an extension for ActionView to allowing invalid date and
293
+ time values to be redisplayed to the user as feedback, instead of a blank
294
+ field which happens by default in Rails. Though the date helpers make this a
295
+ pretty rare occurrence, given the select dropdowns for each date/time
296
+ component, but it may be something of interest.
297
+
298
+ To activate it, uncomment this line in the initializer:
299
+
300
+ # in the setup block
301
+ config.enable_date_time_select_extension!
302
+
303
+ ## Contributors
304
+
305
+ To see the generous people who have contributed code, take a look at the
306
+ [contributors list][contributors].
307
+
308
+ ## Maintainers
309
+
310
+ * [AppFolio][appfolio]
311
+
312
+ ## License
313
+
314
+ Copyright (c) 2008 Adam Meehan, released under the MIT license
315
+ Copyright (c) 2015 AppFolio, released under the MIT license
316
+
317
+ [appfolio]: http://github.com/appfolio
318
+ [adzap]: http://github.com/adzap
319
+ [timeliness]: http://github.com/adzap/timeliness
320
+ [orm-support]: http://github.com/adzap/validates_timeliness/wiki/ORM-Support
321
+ [plugin-parser]: http://github.com/adzap/validates_timeliness/wiki/Plugin-Parser
322
+ [original]: http://github.com/adzap/validates_timeliness
323
+ [contributors]: http://github.com/appfolio/validates_timeliness/contributors
324
+ [gem-badge]: https://badge.fury.io/rb/ae-validates_timeliness.svg
325
+ [gem]: http://badge.fury.io/rb/ae-validates_timeliness
326
+ [build-badge]: https://travis-ci.org/appfolio/validates_timeliness.svg?branch=appfolio
327
+ [build]: https://travis-ci.org/appfolio/validates_timeliness?branch=appfolio
328
+ [coverage-badge]: https://coveralls.io/repos/appfolio/validates_timeliness/badge.png?branch=appfolio
329
+ [coverage]: https://coveralls.io/r/appfolio/validates_timeliness?branch=appfolio