timezone_field 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/timezone_field.rb +7 -9
- metadata +2 -2
data/lib/timezone_field.rb
CHANGED
@@ -4,22 +4,20 @@ require 'active_support'
|
|
4
4
|
module TimezoneField
|
5
5
|
extend ActiveSupport::Concern
|
6
6
|
|
7
|
-
class ZoneValidator < ActiveModel::
|
8
|
-
def
|
9
|
-
record.
|
10
|
-
|
11
|
-
if value.
|
12
|
-
record.errors[tz_field.to_sym] << 'Unrecognized timezone' if ActiveSupport::TimeZone[value].nil?
|
13
|
-
end
|
7
|
+
class ZoneValidator < ActiveModel::EachValidator
|
8
|
+
def validate_each(record, attribute, value)
|
9
|
+
value = record.send(:read_attribute, attribute)
|
10
|
+
if value.present?
|
11
|
+
record.errors[attribute] << 'Unrecognized timezone' if ActiveSupport::TimeZone[value].nil?
|
14
12
|
end
|
15
13
|
end
|
16
14
|
end
|
17
15
|
|
18
16
|
module ClassMethods
|
19
17
|
def has_timezone_field(field_name)
|
20
|
-
self.timezone_fields ||= []
|
21
18
|
self.timezone_fields << field_name
|
22
19
|
define_timezone_accessors(field_name)
|
20
|
+
validates :"#{field_name}", :zone => true
|
23
21
|
end
|
24
22
|
|
25
23
|
def define_timezone_accessors(field_name)
|
@@ -46,6 +44,6 @@ module TimezoneField
|
|
46
44
|
|
47
45
|
included do
|
48
46
|
class_attribute :timezone_fields
|
49
|
-
|
47
|
+
self.timezone_fields ||= []
|
50
48
|
end
|
51
49
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: timezone_field
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-08-
|
12
|
+
date: 2012-08-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|