has_zone 0.0.1 → 0.0.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.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/has_zone/has_zone.rb +8 -2
- data/lib/has_zone/version.rb +1 -1
- data/spec/has_zone_spec.rb +7 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0a1c519eeebf58d6beadb0a8e4b486681d80cf58
|
4
|
+
data.tar.gz: 1a653b1b8a287b40c85b013f7fdee4375d5fe12d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 412de64b074483785fb2495330554baf4588207aa28384062083132b7280b2c15483a7e0788a5ed3f9a7fed07ee62dc85ca32c0f67d9afab8d134330e854695a
|
7
|
+
data.tar.gz: 2e44919e99ee36b6d444c76181aef15c198b3c26b2e706662d46d1c785794fbed0cd598fd41201fb14d3245ce834c4e61c49f5d73ee5275beef8df3feedb5089
|
data/README.md
CHANGED
data/lib/has_zone/has_zone.rb
CHANGED
@@ -3,8 +3,6 @@ module HasZone
|
|
3
3
|
|
4
4
|
included do
|
5
5
|
|
6
|
-
validates_inclusion_of :time_zone, in: ::ActiveSupport::TimeZone.tzids_map.keys, allow_blank: true, if: :time_zone_changed?
|
7
|
-
|
8
6
|
# This allows the model has the ability to store TimeZone.
|
9
7
|
# Usage:
|
10
8
|
# has_zone with: :time_zone
|
@@ -36,6 +34,14 @@ module HasZone
|
|
36
34
|
@zone = nil
|
37
35
|
write_attribute(options[:with], tz)
|
38
36
|
end
|
37
|
+
|
38
|
+
define_method(:set_utc_time_zone) do
|
39
|
+
send "#{options[:with]}=".to_sym, "Etc/UTC" if send(options[:with]) == "UTC"
|
40
|
+
end
|
41
|
+
|
42
|
+
before_validation :set_utc_time_zone
|
43
|
+
validates_inclusion_of options[:with], in: ::ActiveSupport::TimeZone.tzids_map.keys, allow_blank: true
|
44
|
+
|
39
45
|
end
|
40
46
|
end
|
41
47
|
|
data/lib/has_zone/version.rb
CHANGED
data/spec/has_zone_spec.rb
CHANGED
@@ -3,6 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe HasZone do
|
4
4
|
class Resource
|
5
5
|
include ActiveModel::Validations
|
6
|
+
include ActiveModel::Validations::Callbacks
|
6
7
|
include HasZone
|
7
8
|
attr_accessor :time_zone
|
8
9
|
has_zone with: :time_zone
|
@@ -44,4 +45,10 @@ describe HasZone do
|
|
44
45
|
resource.time_zone.should == "America/Los_Angeles"
|
45
46
|
end
|
46
47
|
|
48
|
+
it "sets UTC time zone to Etc/UTC" do
|
49
|
+
resource.time_zone = "UTC"
|
50
|
+
resource.should be_valid
|
51
|
+
resource.time_zone.should == "Etc/UTC"
|
52
|
+
end
|
53
|
+
|
47
54
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: has_zone
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jerry Luk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-08-
|
11
|
+
date: 2013-08-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|