time_jawn 1.0.1 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/time_jawn/time_jawn.rb +9 -3
- data/spec/time_jawn_spec.rb +20 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
N2Q3Zjk3MjhhNGY0OGY2MTg5YzUxMWU2NDlmZmM0MjdmMzI4NmM2NQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZjQ2MzVhNjJiNjlkYjFlZDAyOGU5NzJhNDRmMDg1OGJkYWRjNDNmZQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YzNiYWNhNjZkMzBjYzM2M2JjZmU1MzdhZjQ0MDE3ODFkYjAzNDMyODhkYTgw
|
10
|
+
MjE5NmZjOWE4ODVjZDY5ZTU3NmE1YmFmMjAwZWU0YmNmNDBlZmE1NmQwYzk4
|
11
|
+
YmIxMDk3YTA2NGUwNWEyOWM4N2FhNTBlNzM3NWIzNzBiYmI1ZWU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NTFjMDlhYTE2NTUwYmU0MmJhMzdhOWZlNDkzNzFhMzg3NzZhYWJjODk0MGIz
|
14
|
+
NWVmODdlOWZhNzM4OTRkNWE4YjdiNGZiZmI2ODBiNTg2NDdjNTQ5NDc2ZmE0
|
15
|
+
ZTA0NzA0ZWE1YmMwOTY0ZGU2MmY4NTM2N2I5MTAyMGU3ZDcwZTY=
|
data/lib/time_jawn/time_jawn.rb
CHANGED
@@ -44,12 +44,18 @@ module TimeJawn
|
|
44
44
|
# Defines methods that will attached to all ActiveRecord classes.
|
45
45
|
module ClassMethods
|
46
46
|
include TimeJawnPrivateClassMethods
|
47
|
+
attr_reader :time_zone_attribute_name
|
47
48
|
# When called it loads the methods located in InstanceMethods.
|
48
49
|
# It is typically included in a model's rb file so that instances of that class gain the InstanceMethods at each instantiation.
|
49
50
|
# class Event<ActiveRecord::Base
|
50
51
|
# has_time_zone
|
51
52
|
# end
|
52
|
-
|
53
|
+
# Optionally you may pass the name of your time zone attribute in as a symbol.
|
54
|
+
# class Event<ActiveRecord::Base
|
55
|
+
# has_time_zone :this_is_my_time_zone
|
56
|
+
# end
|
57
|
+
def has_time_zone(time_zone_attribute_name=:time_zone)
|
58
|
+
@time_zone_attribute_name = time_zone_attribute_name
|
53
59
|
send :include, InstanceMethods
|
54
60
|
end
|
55
61
|
end
|
@@ -103,14 +109,14 @@ module TimeJawn
|
|
103
109
|
# converts a time object into it's local counter part (they will have the same value but differnt presentation.)
|
104
110
|
def _to_local(time)
|
105
111
|
ActiveSupport::Deprecation.warn "_to_local will be made private in a future version."
|
106
|
-
time.in_time_zone(self.
|
112
|
+
time.in_time_zone(self.send(self.class.time_zone_attribute_name))
|
107
113
|
end
|
108
114
|
|
109
115
|
# Given a string that looks like a time. It will convert that string into a time object that matches the time but with
|
110
116
|
# the instances time zone appended.
|
111
117
|
def _add_zone(time_string)
|
112
118
|
ActiveSupport::Deprecation.warn "_add_zone will be made private in a future version."
|
113
|
-
Time.zone = self.
|
119
|
+
Time.zone = self.send(self.class.time_zone_attribute_name)
|
114
120
|
Time.zone.parse(time_string)
|
115
121
|
end
|
116
122
|
|
data/spec/time_jawn_spec.rb
CHANGED
@@ -190,3 +190,23 @@ describe Happening do
|
|
190
190
|
end
|
191
191
|
end
|
192
192
|
end
|
193
|
+
|
194
|
+
describe Event do
|
195
|
+
before do
|
196
|
+
@event1 = Event.find_by_name('Eastern Time (US & Canada)')
|
197
|
+
end
|
198
|
+
context "Event should have time_jawn methods even though it has a non_conventional attribute" do
|
199
|
+
subject { @event1 }
|
200
|
+
|
201
|
+
it { should respond_to :local_start_time }
|
202
|
+
it { should respond_to :local_created_at }
|
203
|
+
it { should respond_to :local_updated_at }
|
204
|
+
it { should respond_to :local_start_time= }
|
205
|
+
it { should respond_to :local_created_at= }
|
206
|
+
it { should respond_to :local_updated_at= }
|
207
|
+
it { should respond_to :current_time }
|
208
|
+
it { should respond_to :_to_local }
|
209
|
+
it { should respond_to :_add_zone }
|
210
|
+
it { should respond_to :_change_zone }
|
211
|
+
end
|
212
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: time_jawn
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Platt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-10-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|