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

Class Method Details

.parserObject



11
12
13
# File 'lib/date_time_attribute.rb', line 11

def self.parser
  DateTimeAttribute::Container.parser
end

.parser=(val) ⇒ Object

Parameters:

  • val

    Any adapter responding to #parse



16
17
18
# File 'lib/date_time_attribute.rb', line 16

def self.parser=(val)
  DateTimeAttribute::Container.parser = val
end

Instance Method Details

#date_time_container(attribute) ⇒ Container

Parameters:

  • attribute (Symbol)

Returns:



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

Parameters:

  • zone (String, Symbol, Proc, nil)

    Time zone



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