gbdev-validates_as_date_time 0.5.1 → 0.5.2
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.
- data/CHANGELOG +3 -0
- data/README +4 -2
- data/lib/validates_as_date_time.rb +12 -9
- metadata +2 -2
data/CHANGELOG
CHANGED
data/README
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
ValidatesAsDateTime
|
2
2
|
===================
|
3
3
|
This Ruby on Rails gem/plugin implements an ActiveRecord validation helper called
|
4
|
-
validates_as_date_time which validates U.S. dates, times, or date-times.
|
5
|
-
strings, and ruby Date, Time, or DateTime objects.
|
4
|
+
validates_as_date_time which validates U.S. dates, times, or date-times.
|
6
5
|
|
7
6
|
Installation:
|
8
7
|
=============
|
@@ -20,6 +19,9 @@ In your model file do something like:
|
|
20
19
|
|
21
20
|
class MyClass < ActiveRecord::Base
|
22
21
|
validates_as_date_time :my_birth_date, :year_range => 1980..2005, :allow_nil => false
|
22
|
+
validates_as_date :her_birth_date, :allow_nil => false, :on => :create
|
23
|
+
validates_as_time :his_birth_date, :allow_nil => false, :on => :update
|
24
|
+
|
23
25
|
end
|
24
26
|
|
25
27
|
Tests:
|
@@ -30,7 +30,8 @@ module ActiveRecord
|
|
30
30
|
configuration = {
|
31
31
|
:message => 'is an invalid time',
|
32
32
|
:with => /^#{regExpStr}$/,
|
33
|
-
:allow_nil => false
|
33
|
+
:allow_nil => false,
|
34
|
+
:on => :save }
|
34
35
|
|
35
36
|
configuration.update(attr_names.pop) if attr_names.last.is_a?(Hash)
|
36
37
|
|
@@ -55,10 +56,11 @@ module ActiveRecord
|
|
55
56
|
def validates_as_date(*attr_names)
|
56
57
|
regExpStr = '(([0-1]?[0-9])\/[0-3]?[0-9]\/[0-9]{4})'
|
57
58
|
configuration = {
|
58
|
-
:message
|
59
|
-
:with
|
60
|
-
:allow_nil
|
61
|
-
:year_range => nil
|
59
|
+
:message => 'is an invalid date',
|
60
|
+
:with => /^#{regExpStr}$/,
|
61
|
+
:allow_nil => false,
|
62
|
+
:year_range => nil,
|
63
|
+
:on => :save }
|
62
64
|
|
63
65
|
configuration.update(attr_names.pop) if attr_names.last.is_a?(Hash)
|
64
66
|
|
@@ -85,10 +87,11 @@ module ActiveRecord
|
|
85
87
|
def validates_as_date_time(*attr_names)
|
86
88
|
regExpStr = '(([0-1]?[0-9])\/[0-3]?[0-9]\/[0-9]{4}) *([0-9]{1,2}(:[0-9]{2})? *(am|pm))?'
|
87
89
|
configuration = {
|
88
|
-
:message
|
89
|
-
:with
|
90
|
-
:allow_nil
|
91
|
-
:year_range => nil
|
90
|
+
:message => 'is an invalid datetime',
|
91
|
+
:with => /^#{regExpStr}$/,
|
92
|
+
:allow_nil => false,
|
93
|
+
:year_range => nil,
|
94
|
+
:on => :save }
|
92
95
|
|
93
96
|
configuration.update(attr_names.pop) if attr_names.last.is_a?(Hash)
|
94
97
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gbdev-validates_as_date_time
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wes Hays
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2008-08
|
13
|
+
date: 2008-09-08 00:00:00 -07:00
|
14
14
|
default_executable:
|
15
15
|
dependencies: []
|
16
16
|
|