mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-22 22:06:45 +00:00
Compare commits
10 Commits
v5.0.0.alp
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
16221ac092 | ||
|
|
c0c42edd3f | ||
|
|
f8b91e9cea | ||
|
|
7fa4d85ee3 | ||
|
|
70307293c6 | ||
|
|
f42e905cd1 | ||
|
|
35eb50aa40 | ||
|
|
3134072f01 | ||
|
|
797ba48036 | ||
|
|
f8e6480f58 |
2
Gemfile
2
Gemfile
@ -2,7 +2,7 @@ source 'http://rubygems.org'
|
||||
|
||||
gemspec
|
||||
|
||||
gem 'rails', '~> 5.0.0'
|
||||
gem 'rails', '~> 5.2.4'
|
||||
gem 'rspec'
|
||||
gem 'rspec-rails', '~> 3.7'
|
||||
gem 'timecop'
|
||||
|
||||
34
README.rdoc
34
README.rdoc
@ -30,7 +30,7 @@ If you a looking for the old version for Rails 4.x go here [https://github.com/a
|
||||
== Installation
|
||||
|
||||
# in Gemfile
|
||||
gem 'validates_timeliness', '~> 5.0.0.alpha3'
|
||||
gem 'validates_timeliness', '~> 5.0.0.beta1'
|
||||
|
||||
# Run bundler
|
||||
$ bundle install
|
||||
@ -49,21 +49,21 @@ NOTE: You may wish to enable the plugin parser and the extensions to start. Plea
|
||||
|
||||
validates_datetime :occurred_at
|
||||
|
||||
validates_date :date_of_birth, :before => lambda { 18.years.ago },
|
||||
:before_message => "must be at least 18 years old"
|
||||
validates_date :date_of_birth, before: lambda { 18.years.ago },
|
||||
before_message: "must be at least 18 years old"
|
||||
|
||||
validates_datetime :finish_time, :after => :start_time # Method symbol
|
||||
validates_datetime :finish_time, after: :start_time # Method symbol
|
||||
|
||||
validates_date :booked_at, :on => :create, :on_or_after => :today # See Restriction Shorthand.
|
||||
validates_date :booked_at, on: :create, on_or_after: :today # See Restriction Shorthand.
|
||||
|
||||
validates_time :booked_at, :between => ['9:00am', '5:00pm'] # On or after 9:00AM and on or before 5:00PM
|
||||
validates_time :booked_at, :between => '9:00am'..'5:00pm' # The same as previous example
|
||||
validates_time :booked_at, :between => '9:00am'...'5:00pm' # On or after 9:00AM and strictly before 5:00PM
|
||||
validates_time :booked_at, between: ['9:00am', '5:00pm'] # On or after 9:00AM and on or before 5:00PM
|
||||
validates_time :booked_at, between: '9:00am'..'5:00pm' # The same as previous example
|
||||
validates_time :booked_at, between: '9:00am'...'5:00pm' # On or after 9:00AM and strictly before 5:00PM
|
||||
|
||||
validates_time :breakfast_time, :on_or_after => '6:00am',
|
||||
:on_or_after_message => 'must be after opening time',
|
||||
:before => :lunchtime,
|
||||
:before_message => 'must be before lunch time'
|
||||
validates_time :breakfast_time, on_or_after: '6:00am',
|
||||
on_or_after_message: 'must be after opening time',
|
||||
before: :lunchtime,
|
||||
before_message: 'must be before lunch time'
|
||||
|
||||
|
||||
== Usage
|
||||
@ -72,14 +72,14 @@ To validate a model with a date, time or datetime attribute you just use the
|
||||
validation method
|
||||
|
||||
class Person < ActiveRecord::Base
|
||||
validates_date :date_of_birth, :on_or_before => lambda { Date.current }
|
||||
validates_date :date_of_birth, on_or_before: lambda { Date.current }
|
||||
# or
|
||||
validates :date_of_birth, :timeliness => {:on_or_before => lambda { Date.current }, :type => :date}
|
||||
validates :date_of_birth, timeliness: {on_or_before: lambda { Date.current }, type: :date}
|
||||
end
|
||||
|
||||
or even on a specific record, per ActiveModel API.
|
||||
|
||||
@person.validates_date :date_of_birth, :on_or_before => lambda { Date.current }
|
||||
@person.validates_date :date_of_birth, on_or_before: lambda { Date.current }
|
||||
|
||||
|
||||
The list of validation methods available are as follows:
|
||||
@ -206,14 +206,14 @@ plugin allows you to use shorthand symbols for often used relative times or date
|
||||
|
||||
Just provide the symbol as the option value like so:
|
||||
|
||||
validates_date :birth_date, :on_or_before => :today
|
||||
validates_date :birth_date, on_or_before: :today
|
||||
|
||||
The :today symbol is evaluated as <tt>lambda { Date.today }</tt>. The :now and :today
|
||||
symbols are pre-configured. Configure your own like so:
|
||||
|
||||
# in the setup block
|
||||
config.restriction_shorthand_symbols.update(
|
||||
:yesterday => lambda { 1.day.ago }
|
||||
yesterday: lambda { 1.day.ago }
|
||||
)
|
||||
|
||||
|
||||
|
||||
@ -12,7 +12,7 @@ module ValidatesTimeliness
|
||||
ValidatesTimeliness.ignore_restriction_errors = !Rails.env.test?
|
||||
end
|
||||
|
||||
initializer "validates_timeliness.initialize_timeliness_ambiguous_date_format", :after => 'load_config_initializers' do
|
||||
initializer "validates_timeliness.initialize_timeliness_ambiguous_date_format", :after => :load_config_initializers do
|
||||
if Timeliness.respond_to?(:ambiguous_date_format) # i.e. v0.4+
|
||||
# Set default for each new thread if you have changed the default using
|
||||
# the format switching methods.
|
||||
|
||||
@ -1,3 +1,3 @@
|
||||
module ValidatesTimeliness
|
||||
VERSION = '5.0.0.alpha5'
|
||||
VERSION = '5.0.0.beta2'
|
||||
end
|
||||
|
||||
@ -17,8 +17,7 @@ module ModelHelpers
|
||||
|
||||
def with_each_person_value(attr_name, values)
|
||||
record = Person.new
|
||||
values = [values] unless values.is_a?(Array)
|
||||
values.each do |value|
|
||||
Array.wrap(values).each do |value|
|
||||
record.send("#{attr_name}=", value)
|
||||
yield record, value
|
||||
end
|
||||
|
||||
Loading…
Reference in New Issue
Block a user