module Safely
Constants
- DEFAULT_EXCEPTION_METHOD
- VERSION
Attributes
env[W]
raise_envs[RW]
report_exception_method[RW]
tag[RW]
throttle_counter[RW]
Public Class Methods
env()
click to toggle source
# File lib/safely/core.rb, line 29 def env @env ||= ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development" end
report_exception(e, tag: nil, context: {})
click to toggle source
# File lib/safely/core.rb, line 13 def report_exception(e, tag: nil, context: {}) tag = Safely.tag if tag.nil? if tag && e.message e = e.dup # leave original exception unmodified message = e.message e.define_singleton_method(:message) do "[#{tag == true ? "safely" : tag}] #{message}" end end if report_exception_method.arity == 1 report_exception_method.call(e) else report_exception_method.call(e, context) end end
throttled?(e, options)
click to toggle source
# File lib/safely/core.rb, line 33 def throttled?(e, options) return false unless options key = "#{options[:key] || Digest::MD5.hexdigest([e.class.name, e.message, e.backtrace.join("\n")].join("/"))}/#{(Time.now.to_i / options[:period]) * options[:period]}" throttle_counter.clear if throttle_counter.size > 1000 # prevent from growing indefinitely (throttle_counter[key] += 1) > options[:limit] end