module Teasy::PeriodNotFoundHandling::ClassMethods

Constants

HANDLER

Public Instance Methods

period_not_found_handler() click to toggle source
# File lib/teasy/period_not_found_handling.rb, line 12
def period_not_found_handler
  Thread.current[:teasy_period_not_found_handler] ||= HANDLER[:raise]
end
period_not_found_handler=(name_or_callable) click to toggle source
# File lib/teasy/period_not_found_handling.rb, line 16
def period_not_found_handler=(name_or_callable)
  if name_or_callable.respond_to?(:call)
    Thread.current[:teasy_period_not_found_handler] = name_or_callable
  else
    Thread.current[:teasy_period_not_found_handler] = HANDLER.fetch(
      name_or_callable.to_sym
    ) do |key|
      raise UnknownPeriodNotFoundHandler,
            "Don't know a PeriodNotFound handler `#{key}`."
    end
  end
end
with_period_not_found_handler(handler) { || ... } click to toggle source
# File lib/teasy/period_not_found_handling.rb, line 29
def with_period_not_found_handler(handler)
  old_handler = period_not_found_handler
  self.period_not_found_handler = handler
  yield
ensure
  self.period_not_found_handler = old_handler
end