has_zone 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 53371fa0b22046704af05bf67038f0d12b06965c
4
- data.tar.gz: be7aff3caed35d3c9abb5f552a5f969803e2911f
3
+ metadata.gz: 0a1c519eeebf58d6beadb0a8e4b486681d80cf58
4
+ data.tar.gz: 1a653b1b8a287b40c85b013f7fdee4375d5fe12d
5
5
  SHA512:
6
- metadata.gz: 0f49581efb0258ad9566ebfd07dfbe505f7b08195c4728eb702b31a4a6f20b9e204e68357a462c4192c23aad23baf5ec76ac807e19b2fa6ea84baf56783bda8f
7
- data.tar.gz: ca81dbaf1c9ed288391f3d9955f41ee805958231a5b5c470c42136900ff4c077ec67ec292f8515455bc86c3df31ffc8aecd4916b3cb90bc052c34549b97d64dd
6
+ metadata.gz: 412de64b074483785fb2495330554baf4588207aa28384062083132b7280b2c15483a7e0788a5ed3f9a7fed07ee62dc85ca32c0f67d9afab8d134330e854695a
7
+ data.tar.gz: 2e44919e99ee36b6d444c76181aef15c198b3c26b2e706662d46d1c785794fbed0cd598fd41201fb14d3245ce834c4e61c49f5d73ee5275beef8df3feedb5089
data/README.md CHANGED
@@ -22,7 +22,7 @@ Assuming you have an attribute time_zone in your User model:
22
22
 
23
23
  class User < ActiveRecord::Base
24
24
  include HasZone
25
- has_zone with: time_zone
25
+ has_zone with: :time_zone
26
26
  end
27
27
 
28
28
  Then you can use the time zone with:
@@ -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
 
@@ -1,3 +1,3 @@
1
1
  module HasZone
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -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.1
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-13 00:00:00.000000000 Z
11
+ date: 2013-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport