Compare commits

..

No commits in common. "master" and "v5.0.0.alpha5" have entirely different histories.

5 changed files with 22 additions and 21 deletions

View File

@ -2,7 +2,7 @@ source 'http://rubygems.org'
gemspec
gem 'rails', '~> 5.2.4'
gem 'rails', '~> 5.0.0'
gem 'rspec'
gem 'rspec-rails', '~> 3.7'
gem 'timecop'

View File

@ -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.beta1'
gem 'validates_timeliness', '~> 5.0.0.alpha3'
# 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 }
)

View File

@ -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.

View File

@ -1,3 +1,3 @@
module ValidatesTimeliness
VERSION = '5.0.0.beta2'
VERSION = '5.0.0.alpha5'
end

View File

@ -17,7 +17,8 @@ module ModelHelpers
def with_each_person_value(attr_name, values)
record = Person.new
Array.wrap(values).each do |value|
values = [values] unless values.is_a?(Array)
values.each do |value|
record.send("#{attr_name}=", value)
yield record, value
end