Module: DateTimeAttribute
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/date_time_attribute.rb,
lib/date_time_attribute/container.rb
Defined Under Namespace
Modules: ClassMethods
Classes: Container
Constant Summary
collapse
- VERSION =
'0.0.7'
Class Method Summary
collapse
Instance Method Summary
collapse
Instance Method Details
#date_time_container(attribute) ⇒ Container
22
23
24
|
# File 'lib/date_time_attribute.rb', line 22
def date_time_container(attribute)
(@date_time_container ||= {})[attribute] ||= DateTimeAttribute::Container.new(send(attribute))
end
|
#in_time_zone(zone) ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/date_time_attribute.rb', line 27
def in_time_zone(zone)
case zone
when nil
yield
when ActiveSupport::TimeZone, String
old_zone = Time.zone
Time.zone = zone
yield(zone).tap { Time.zone = old_zone }
when Proc, Symbol
old_zone = Time.zone
zone = instance_eval(&(zone.to_proc))
Time.zone = zone
yield(zone).tap { Time.zone = old_zone }
else
raise ArgumentError, "Expected timezone, got #{zone.inspect}"
end
end
|