Compare commits

..

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

4 changed files with 20 additions and 20 deletions

View File

@ -2,7 +2,7 @@ source 'http://rubygems.org'
gemspec gemspec
gem 'rails', '~> 5.2.4' gem 'rails', '~> 5.1.7'
gem 'rspec' gem 'rspec'
gem 'rspec-rails', '~> 3.7' gem 'rspec-rails', '~> 3.7'
gem 'timecop' 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 == Installation
# in Gemfile # in Gemfile
gem 'validates_timeliness', '~> 5.0.0.beta1' gem 'validates_timeliness', '~> 5.0.0.alpha3'
# Run bundler # Run bundler
$ bundle install $ 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_datetime :occurred_at
validates_date :date_of_birth, before: lambda { 18.years.ago }, validates_date :date_of_birth, :before => lambda { 18.years.ago },
before_message: "must be at least 18 years old" :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'] # 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' # 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 strictly before 5:00PM
validates_time :breakfast_time, on_or_after: '6:00am', validates_time :breakfast_time, :on_or_after => '6:00am',
on_or_after_message: 'must be after opening time', :on_or_after_message => 'must be after opening time',
before: :lunchtime, :before => :lunchtime,
before_message: 'must be before lunch time' :before_message => 'must be before lunch time'
== Usage == Usage
@ -72,14 +72,14 @@ To validate a model with a date, time or datetime attribute you just use the
validation method validation method
class Person < ActiveRecord::Base 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 # 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 end
or even on a specific record, per ActiveModel API. 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: 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: 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 The :today symbol is evaluated as <tt>lambda { Date.today }</tt>. The :now and :today
symbols are pre-configured. Configure your own like so: symbols are pre-configured. Configure your own like so:
# in the setup block # in the setup block
config.restriction_shorthand_symbols.update( 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? ValidatesTimeliness.ignore_restriction_errors = !Rails.env.test?
end 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+ if Timeliness.respond_to?(:ambiguous_date_format) # i.e. v0.4+
# Set default for each new thread if you have changed the default using # Set default for each new thread if you have changed the default using
# the format switching methods. # the format switching methods.

View File

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