module Teasy::AmbiguousTimeHandling::ClassMethods

Constants

HANDLER

Public Instance Methods

ambiguous_time_handler() click to toggle source
# File lib/teasy/ambiguous_time_handling.rb, line 11
def ambiguous_time_handler
  Thread.current[:teasy_ambiguous_time_handler] ||= HANDLER[:raise]
end
ambiguous_time_handler=(name_or_callable) click to toggle source
# File lib/teasy/ambiguous_time_handling.rb, line 15
def ambiguous_time_handler=(name_or_callable)
  if name_or_callable.respond_to?(:call)
    Thread.current[:teasy_ambiguous_time_handler] = name_or_callable
  else
    Thread.current[:teasy_ambiguous_time_handler] = HANDLER.fetch(
      name_or_callable.to_sym
    ) do |key|
      raise UnknownAmbiguousTimeHandler,
            "Don't know an ambiguous time handler `#{key}`."
    end
  end
end
with_ambiguous_time_handler(handler) { || ... } click to toggle source
# File lib/teasy/ambiguous_time_handling.rb, line 28
def with_ambiguous_time_handler(handler)
  old_handler = ambiguous_time_handler
  self.ambiguous_time_handler = handler
  yield
ensure
  self.ambiguous_time_handler = old_handler
end