validates_timeliness 6.0.0.beta1 → 6.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc DELETED
@@ -1,222 +0,0 @@
1
- = 5.0.0 [2021-04-03]
2
- * Fix DateTimeSelect extension support (AquisTech)
3
- * Relaxed Timeliness dependency version which allows for >= 0.4.0 with
4
- threadsafety fix for use_us_formats and use_euro_formats for hot switching
5
- in a request.
6
- * Add initializer to ensure Timeliness v0.4+ ambiguous date config is set
7
- correctly when using `use_euro_formats` or `remove_use_formats'.
8
- * Add Ruby 3 compatibility
9
- * Add Rails 6.1 compatibility
10
-
11
- Breaking Changes
12
- * Update Multiparameter extension to use ActiveRecord type classes with multiparameter handling
13
- which stores a hash of multiparamter values as the value before type cast, no longer a mushed datetime string
14
- * Removed all custom plugin attribute methods and method overrides in favour using ActiveModel type system
15
-
16
- = 4.1.0 [2019-06-11]
17
- * Relaxed Timeliness dependency version to >= 0.3.10 and < 1, which allows
18
- version 0.4 with threadsafety fix for use_us_formats and use_euro_formats
19
- hot switching in a request.
20
-
21
- = 4.0.2 [2016-01-07]
22
- * Fix undefine_generated_methods ivar guard setting to false
23
-
24
- = 4.0.1 [2016-01-06]
25
- * Fix undefine_generated_methods thread locking bug
26
- * Created an ActiveModel ORM, for manual require if using without any full blown ORM
27
-
28
- = 4.0.0 [2015-12-29]
29
- * Extracted mongoid support into https://github.com/adzap/validates_timeliness-mongoid which is broken (not supported anymore).
30
- * Fixed Rails 4.0, 4.1 and 4.2 compatability issues
31
- * Upgrade specs to RSpec 3
32
- * Added travis config
33
- * Huge thanks to @johncarney for keeping it alive with his fork (https://github.com/johncarney/validates_timeliness)
34
-
35
- = 3.0.15 [2015-12-29]
36
- * Fixes mongoid 3 support and removes mongoid 2 support(johnnyshields)
37
- * Some documentation/comments tidying
38
- * Some general tidying up
39
-
40
- = 3.0.14 [2012-08-23]
41
- * Fix for using validates :timeliness => {} form to correctly add attributes to timeliness validated attributes.
42
-
43
- = 3.0.13 [2012-08-21]
44
- * Fix ActiveRecord issues with using plugin parser by using old way of caching values.
45
- * Allow any ActiveRecord non-column attribute to be validated
46
-
47
- = 3.0.12 [2012-06-23]
48
- * Fix load order issue when relying on Railtie to load ActiveRecord extension
49
-
50
- = 3.0.11 [2012-04-01]
51
- * Change dependency on Timeliness version due to a broken release
52
-
53
- = 3.0.10 [2012-03-26]
54
- * Fix for ActiveRecord shim and validation with :allow_blank => true in AR 3.1+. Fixes issue#52.
55
-
56
- = 3.0.9 [2012-03-26]
57
- * ActiveRecord 3.1+ suport
58
- * Fixes for multiparameter extension with empty date values (thanks @mogox, @Sharagoz)
59
-
60
- = 3.0.8 [2011-12-24]
61
- * Remove deprecated InstanceMethods module when using AS::Concern (carlosantoniodasilva)
62
- * Update Mongoid shim for v2.3 compatability.
63
-
64
- = 3.0.7 [2011-09-21]
65
- * Fix ActiveRecord before_type_cast extension for non-dirty attributes.
66
- * Don't override AR before_type_cast for >= 3.1.0 which now has it's own implementation for date/time attributes.
67
- * Fix DateTimeSelect extension to convert params to integers (#45)
68
- * Add #change method to DateTimeSelect extension (@trusche, #45)
69
- * Cleanup Mongoid shim.
70
-
71
- = 3.0.6 [2011-05-09]
72
- * Fix for AR type conversion for date columns when using plugin parser.
73
- * Add timeliness_type_cast_code for ORM specific type casting after parsing.
74
-
75
- = 3.0.5 [2011-01-29]
76
- * Fix for Conversion#parse when given nil value (closes issue #34)
77
-
78
- = 3.0.4 [2011-01-22]
79
- * Fix :between option which was being ignored (ebeigarts)
80
- * Use class_attribute to remove deprecated class_inheritable_accessor
81
- * Namespace copied validator class to ActiveModel::Validations::Timeliness for :timeliness option
82
-
83
- = 3.0.3 [2010-12-11]
84
- * Fix validation of values which don't respond to to_date or to_time (renatoelias)
85
-
86
- = 3.0.2 [2010-12-04]
87
- * Fix AR multiparameter extension for Date columns
88
- * Update to Timeliness 0.3.2 for zone abbreviation and offset support
89
-
90
- = 3.0.1 [2010-11-02]
91
- * Generate timeliness write methods in an included module to allow overriding in model class (josevalim)
92
-
93
- = 3.0.0 [2010-10-18]
94
- * Rails 3 and ActiveModel compatibility
95
- * Uses ActiveModel::EachValidator as validator base class.
96
- * Configuration settings stored in ValidatesTimeliness module only. ValidatesTimeliness.setup block to configure.
97
- * Parser extracted to the Timeliness gem http://github.com/adzap/timeliness
98
- * Parser is disabled by default. See initializer for enabling it.
99
- * Removed RSpec matcher. Encouraged poor specs by copy-pasting from spec to model, or worse, the other way round.
100
- * 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.
101
- * Add validation helpers to classes using extend_orms config setting. e.g. conf.extend_orms = [ :active_record ]
102
- * 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.
103
- * Provides :timeliness option key for validates class method. Be sure to pass :type option as well e.g. :type => :date.
104
- * Allows validation methods to be called on record instances as per ActiveModel API.
105
- * Performs parsing (optional) and raw value caching (before_type_cast) on validated attributes only. It used to be all date, time and datetime attributes.
106
-
107
- = 2.3.1 [2010-03-19]
108
- * Fixed bug where custom attribute writer method for date/times were being overriden
109
-
110
- = 2.3.0 [2010-02-04]
111
- * 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.
112
- * Fixed I18n support so it returns missing translation message instead of error
113
- * Fixed attribute method bug. Write method was bypassed when method was first generated and used Rails default parser.
114
- * Fixed date/time selects when using enable_datetime_select_extension! when some values empty
115
- * Fixed ISO8601 datetime format which is now split into two formats
116
- * Changed I18n error value format to fallback to global default if missing in locale
117
- * Refactored date/time select invalid value extension to use param values. Functionality will be extracted from plugin for v3.
118
-
119
- = 2.2.2 [2009-09-19]
120
- * Fixed dummy_time using make_time to respect timezone. Fixes 1.9.1 bug.
121
-
122
- = 2.2.1 [2009-09-12]
123
- * Fixed dummy date part for time types in Validator.type_cast_value
124
- * No more core extensions! Removed dummy_time methods.
125
-
126
- = 2.2.0 [2009-09-12]
127
- * Ruby 1.9 support!
128
- * Customise dummy date values for time types. See DUMMY DATE FOR TIME TYPES.
129
- * Fixed matcher conflict with Shoulda. Load plugin matcher manually now see matcher section in README
130
- * Fixed :ignore_usec when used with :with_time or :with_date
131
- * Some clean up and refactoring
132
-
133
- = 2.1.0 [2009-06-20]
134
- * Added ambiguous year threshold setting in Formats class to customize the threshold for 2 digit years (See README)
135
- * Fixed interpolation values in custom error message for Rails 2.2+
136
- * Fixed custom I18n local override of en locale
137
- * Dramatically simplified ActiveRecord monkey patching and hackery
138
-
139
- = 2.0.0 [2009-04-12]
140
- * Error value formats are now specified in the i18n locale file instead of updating plugin hash. See OTHER CUSTOMISATION section in README.
141
- * Date/time select helper extension is disabled by default. To enable see DISPLAY INVALID VALUES IN DATE HELPERS section in README to enable.
142
- * Added :format option to limit validation to a single format if desired
143
- * Matcher now supports :equal_to option
144
- * 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.
145
- * Refactored to remove as much plugin code from ActiveRecord as possible.
146
-
147
- = 1.1.7 [2009-03-26]
148
- * Minor change to multiparameter attributes which I had not properly implemented for chaining
149
-
150
- = 1.1.6 [2009-03-19]
151
- * Rail 2.3 support
152
- * 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
153
- * Added :equal_to option
154
- * Option key validation
155
- * Better behaviour with other plugins using alias_method_chain on read_attribute and define_attribute_methods
156
- * Added option to enable datetime_select extension for future use to optionally enable. Enabled by default until version 2.
157
- * Added :ignore_usec option for datetime restrictions to be compared without microsecond
158
- * some refactoring
159
-
160
- = 1.1.5 [2009-01-21]
161
- * 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
162
-
163
- = 1.1.4 [2009-01-13]
164
- * Make months names respect i18n in Formats
165
-
166
- = 1.1.3 [2009-01-13]
167
- * Fixed bug where time and date attributes still being parsed on read using Rails default parser [reported by Brad (pvjq)]
168
-
169
- = 1.1.2 [2009-01-12]
170
- * Fixed bugs
171
- * matcher failing for custom error message without interpolation keys using I18n
172
- * validator custom error messages not being extracted
173
-
174
- = 1.1.1 [2009-01-03]
175
- * Fixed bug in matcher for options local variable
176
-
177
- = 1.1.0 [2009-01-01]
178
- * Added between option
179
-
180
- = 1.0.0 [2008-12-06]
181
- * Gemified!
182
- * Refactor of plugin into a Data Mapper style validator class which makes for a cleaner implementation and possible future Merb\Data Mapper support
183
- * Added Rails 2.2 i18n support. Plugin error messages can specified in locale files. See README.
184
- * ignore_datetime_restriction_errors setting has been moved from AR to ValidatesTimeliness::Validator.ignore_restriction_errors
185
- * date_time_error_value_formats setting has been moved from AR to ValidatesTimeliness::Validator.error_value_formats
186
- * Namespaced modules and specs
187
- * Clean up of specs
188
- * fixed a few bugs
189
- * accessor methods not generating properly due method name stored as symbol in generated_attributes which fails on lookup
190
- * force value assigned to time/datetime attributes to time objects
191
-
192
- = 0.1.0 [2008-12-06]
193
- * Tagged plugin as version 0.1.0
194
-
195
- = 2008-11-13
196
- * allow uppercase meridian to be valid [reported by Alex (http://alex.digns.com/)]
197
-
198
- = 2008-10-28
199
- * fixed bug when dirty attributes not reflecting change when attribute changed from time value to nil [reported by Brad (pvjq)]
200
- * fixes for Rails 2.2 compatibility. Will refactor in to Rails version specific branches in the future.
201
-
202
- = 2008-09-24
203
- * refactored attribute write method definitions
204
-
205
- = 2008-08-25
206
- * fixed bug for non-timezone write method not updating changed attributes hash [reported by Sylvestre Mergulhão]
207
-
208
- = 2008-08-22
209
- * fixed bug with attribute cache not clearing on write for date and time columns [reported by Sylvestre Mergulhão]
210
- * parse method returns Date object for date column assigned string as per normal Rails behaviour
211
- * parse method returns same object type when assigned Date or Time object as per normal Rails behaviour
212
-
213
- = 2008-08-07
214
- * modified matcher option value parsing to allow same value types as validation method
215
- * fixed matcher message
216
-
217
- = 2008-08-02
218
- * refactored validation
219
- * refactored matcher
220
-
221
- = 2008-07-30
222
- * removed setting values to nil when validation fails to preserve before_type_cast value
data/README.rdoc DELETED
@@ -1,303 +0,0 @@
1
- = ValidatesTimeliness {<img src="https://travis-ci.org/adzap/validates_timeliness.svg?branch=master" alt="Build Status" />}[https://travis-ci.org/adzap/validates_timeliness]
2
-
3
- * Source: https://github.com/adzap/validates_timeliness
4
- * Issues: https://github.com/adzap/validates_timeliness/issues
5
-
6
- == Description
7
-
8
- Complete validation of dates, times and datetimes for Rails 6.x and ActiveModel.
9
-
10
- Old Rails versions:
11
-
12
- * Rails 4.x: [https://github.com/adzap/validates_timeliness/tree/4-0-stable]
13
-
14
- * Rails 5.x: [https://github.com/adzap/validates_timeliness/tree/5-0-stable]
15
-
16
-
17
- == Features
18
-
19
- * Adds validation for dates, times and datetimes to ActiveModel
20
-
21
- * Handles timezones and type casting of values for you
22
-
23
- * Only Rails date/time validation plugin offering complete validation (See ORM/ODM support)
24
-
25
- * Uses extensible date/time parser (Using {timeliness gem}[https://github.com/adzap/timeliness]. See Plugin Parser)
26
-
27
- * Adds extensions to fix Rails date/time select issues (See Extensions)
28
-
29
- * Supports I18n for the error messages. For multi-language support try {timeliness-i18n gem}[https://github.com/pedrofurtado/timeliness-i18n].
30
-
31
- * Supports all the Rubies (that any sane person would be using in production).
32
-
33
-
34
- == Installation
35
-
36
- # in Gemfile
37
- gem 'validates_timeliness', '~> 6.0.0.alpha1'
38
-
39
- # Run bundler
40
- $ bundle install
41
-
42
- Then run
43
-
44
- $ rails generate validates_timeliness:install
45
-
46
- This creates configuration initializer and locale files. In the initializer, there are a number of config
47
- options to customize the plugin.
48
-
49
- NOTE: You may wish to enable the plugin parser and the extensions to start. Please read those sections first.
50
-
51
-
52
- == Examples
53
-
54
- validates_datetime :occurred_at
55
-
56
- validates_date :date_of_birth, before: lambda { 18.years.ago },
57
- before_message: "must be at least 18 years old"
58
-
59
- validates_datetime :finish_time, after: :start_time # Method symbol
60
-
61
- validates_date :booked_at, on: :create, on_or_after: :today # See Restriction Shorthand.
62
-
63
- validates_time :booked_at, between: ['9:00am', '5:00pm'] # On or after 9:00AM and on or before 5:00PM
64
- validates_time :booked_at, between: '9:00am'..'5:00pm' # The same as previous example
65
- validates_time :booked_at, between: '9:00am'...'5:00pm' # On or after 9:00AM and strictly before 5:00PM
66
-
67
- validates_time :breakfast_time, on_or_after: '6:00am',
68
- on_or_after_message: 'must be after opening time',
69
- before: :lunchtime,
70
- before_message: 'must be before lunch time'
71
-
72
-
73
- == Usage
74
-
75
- To validate a model with a date, time or datetime attribute you just use the
76
- validation method
77
-
78
- class Person < ActiveRecord::Base
79
- validates_date :date_of_birth, on_or_before: lambda { Date.current }
80
- # or
81
- validates :date_of_birth, timeliness: {on_or_before: lambda { Date.current }, type: :date}
82
- end
83
-
84
- or even on a specific record, per ActiveModel API.
85
-
86
- @person.validates_date :date_of_birth, on_or_before: lambda { Date.current }
87
-
88
-
89
- The list of validation methods available are as follows:
90
- validates_date - validate value as date
91
- validates_time - validate value as time only i.e. '12:20pm'
92
- validates_datetime - validate value as a full date and time
93
- validates - use the :timeliness key and set the type in the hash.
94
-
95
- The validation methods take the usual options plus some specific ones to restrict
96
- the valid range of dates or times allowed
97
-
98
- Temporal options (or restrictions):
99
- :is_at - Attribute must be equal to value to be valid
100
- :before - Attribute must be before this value to be valid
101
- :on_or_before - Attribute must be equal to or before this value to be valid
102
- :after - Attribute must be after this value to be valid
103
- :on_or_after - Attribute must be equal to or after this value to be valid
104
- :between - Attribute must be between the values to be valid. Range or Array of 2 values.
105
-
106
- Regular validation options:
107
- :allow_nil - Allow a nil value to be valid
108
- :allow_blank - Allows a nil or empty string value to be valid
109
- :if - Execute validation when :if evaluates true
110
- :unless - Execute validation when :unless evaluates false
111
- :on - Specify validation context e.g :save, :create or :update. Default is :save.
112
-
113
- Special options:
114
- :ignore_usec - Ignores microsecond value on datetime restrictions
115
- :format - Limit validation to a single format for special cases. Requires plugin parser.
116
-
117
- The temporal restrictions can take 4 different value types:
118
-
119
- * Date, Time, or DateTime object value
120
- * Proc or lambda object which may take an optional parameter, being the record object
121
- * A symbol matching a method name in the model
122
- * String value
123
-
124
- When an attribute value is compared to temporal restrictions, they are compared as
125
- the same type as the validation method type. So using validates_date means all
126
- values are compared as dates.
127
-
128
-
129
- == Configuration
130
-
131
- === ORM/ODM Support
132
-
133
- The plugin adds date/time validation to ActiveModel for any ORM/ODM that supports the ActiveModel validations component.
134
- However, there is an issue with most ORM/ODMs which does not allow 100% date/time validation by default. Specifically, when you
135
- assign an invalid date/time value to an attribute, most ORM/ODMs will only store a nil value for the attribute. This causes an
136
- issue for date/time validation, since we need to know that a value was assigned but was invalid. To fix this, we need to cache
137
- the original invalid value to know that the attribute is not just nil.
138
-
139
- Each ORM/ODM requires a specific shim to fix it. The plugin includes a shim for ActiveRecord and Mongoid. You can activate them
140
- like so
141
-
142
- ValidatesTimeliness.setup do |config|
143
-
144
- # Extend ORM/ODMs for full support (:active_record).
145
- config.extend_orms = [ :active_record ]
146
-
147
- end
148
-
149
- By default the plugin extends ActiveRecord if loaded. If you wish to extend another ORM then look at the {wiki page}[https://github.com/adzap/validates_timeliness/wiki/ORM-Support] for more information.
150
-
151
- It is not required that you use a shim, but you will not catch errors when the attribute value is invalid and evaluated to nil.
152
-
153
-
154
- === Error Messages
155
-
156
- Using the I18n system to define new defaults:
157
-
158
- en:
159
- errors:
160
- messages:
161
- invalid_date: "is not a valid date"
162
- invalid_time: "is not a valid time"
163
- invalid_datetime: "is not a valid datetime"
164
- is_at: "must be at %{restriction}"
165
- before: "must be before %{restriction}"
166
- on_or_before: "must be on or before %{restriction}"
167
- after: "must be after %{restriction}"
168
- on_or_after: "must be on or after %{restriction}"
169
-
170
- The %{restriction} signifies where the interpolation value for the restriction will be inserted.
171
-
172
- You can also use validation options for custom error messages. The following option keys are available:
173
-
174
- :invalid_date_message
175
- :invalid_time_message
176
- :invalid_datetime_message
177
- :is_at_message
178
- :before_message
179
- :on_or_before_message
180
- :after_message
181
- :on_or_after_message
182
-
183
- Note: There is no :between_message option. The between error message should be defined using the :on_or_after and :on_or_before
184
- (:before in case when :between argument is a Range with excluded high value, see Examples) messages.
185
-
186
- It is highly recommended you use the I18n system for error messages.
187
-
188
-
189
- === Plugin Parser
190
-
191
- The plugin uses the {timeliness gem}[https://github.com/adzap/timeliness] as a fast, configurable and extensible date and time parser.
192
- You can add or remove valid formats for dates, times, and datetimes. It is also more strict than the
193
- Ruby parser, which means it won't accept day of the month if it's not a valid number for the month.
194
-
195
- By default the parser is disabled. To enable it:
196
-
197
- # in the setup block
198
- config.use_plugin_parser = true
199
-
200
- Enabling the parser will mean that strings assigned to attributes validated with the plugin will be parsed
201
- using the gem. See the wiki[https://github.com/adzap/validates_timeliness/wiki/Plugin-Parser] for more details about the parser configuration.
202
-
203
-
204
- === Restriction Shorthand
205
-
206
- It is common to restrict an attribute to being on or before the current time or current day.
207
- To specify this you need to use a lambda as an option value e.g. <tt>lambda { Time.current }</tt>.
208
- This can be tedious noise amongst your validations for something so common. To combat this the
209
- plugin allows you to use shorthand symbols for often used relative times or dates.
210
-
211
- Just provide the symbol as the option value like so:
212
-
213
- validates_date :birth_date, on_or_before: :today
214
-
215
- The :today symbol is evaluated as <tt>lambda { Date.current }</tt>. The :now and :today
216
- symbols are pre-configured. Configure your own like so:
217
-
218
- # in the setup block
219
- config.restriction_shorthand_symbols.update(
220
- yesterday: lambda { 1.day.ago }
221
- )
222
-
223
-
224
- === Default Timezone
225
-
226
- The plugin needs to know the default timezone you are using when parsing or type casting values. If you are using
227
- ActiveRecord then the default is automatically set to the same default zone as ActiveRecord. If you are using
228
- another ORM you may need to change this setting.
229
-
230
- # in the setup block
231
- config.default_timezone = :utc
232
-
233
- By default it will be UTC if ActiveRecord is not loaded.
234
-
235
-
236
- === Dummy Date For Time Types
237
-
238
- Given that Ruby has no support for a time-only type, all time type columns are evaluated
239
- as a regular Time class objects with a dummy date value set. Rails defines the dummy date as
240
- 2000-01-01. So a time of '12:30' is evaluated as a Time value of '2000-01-01 12:30'. If you
241
- need to customize this for some reason you can do so as follows
242
-
243
- # in the setup block
244
- config.dummy_date_for_time_type = [2009, 1, 1]
245
-
246
- The value should be an array of 3 values being year, month and day in that order.
247
-
248
-
249
- === Temporal Restriction Errors
250
-
251
- When using the validation temporal restrictions there are times when the restriction
252
- option value itself may be invalid. This will add an error to the model such as
253
- 'Error occurred validating birth_date for :before restriction'. These can be annoying
254
- in development or production as you most likely just want to skip the option if no
255
- valid value was returned. By default these errors are displayed in Rails test mode.
256
-
257
- To turn them on/off:
258
-
259
- # in the setup block
260
- config.ignore_restriction_errors = true
261
-
262
-
263
- == Extensions
264
-
265
- === Strict Parsing for Select Helpers
266
-
267
- When using date/time select helpers, the component values are handled by ActiveRecord using
268
- the Time class to instantiate them into a time value. This means that some invalid dates,
269
- such as 31st June, are shifted forward and treated as valid. To handle these cases in a strict
270
- way, you can enable the plugin extension to treat them as invalid dates.
271
-
272
- To activate it, uncomment this line in the initializer:
273
-
274
- # in the setup block
275
- config.enable_multiparameter_extension!
276
-
277
-
278
- === Display Invalid Values in Select Helpers
279
-
280
- The plugin offers an extension for ActionView to allowing invalid date and time values to be
281
- redisplayed to the user as feedback, instead of a blank field which happens by default in
282
- Rails. Though the date helpers make this a pretty rare occurrence, given the select dropdowns
283
- for each date/time component, but it may be something of interest.
284
-
285
- To activate it, uncomment this line in the initializer:
286
-
287
- # in the setup block
288
- config.enable_date_time_select_extension!
289
-
290
-
291
- == Contributors
292
-
293
- To see the generous people who have contributed code, take a look at the {contributors list}[https://github.com/adzap/validates_timeliness/contributors].
294
-
295
-
296
- == Maintainers
297
-
298
- * {Adam Meehan}[https://github.com/adzap]
299
-
300
-
301
- == License
302
-
303
- Copyright (c) 2008 Adam Meehan, released under the MIT license