Module: Safely

Extended by:
Methods
Defined in:
lib/safely/core.rb,
lib/safely/version.rb

Defined Under Namespace

Modules: Methods

Constant Summary collapse

DEFAULT_EXCEPTION_METHOD =
proc do |e|
  Errbase.report(e)
end
VERSION =
"0.2.0"

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from Methods

safely

Class Attribute Details

.envObject



14
15
16
# File 'lib/safely/core.rb', line 14

def env
  @env ||= ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development"
end

.raise_envsObject

Returns the value of attribute raise_envs.



7
8
9
# File 'lib/safely/core.rb', line 7

def raise_envs
  @raise_envs
end

.report_exception_methodObject

Returns the value of attribute report_exception_method.



7
8
9
# File 'lib/safely/core.rb', line 7

def report_exception_method
  @report_exception_method
end

.tagObject

Returns the value of attribute tag.



7
8
9
# File 'lib/safely/core.rb', line 7

def tag
  @tag
end

.throttle_counterObject

Returns the value of attribute throttle_counter.



7
8
9
# File 'lib/safely/core.rb', line 7

def throttle_counter
  @throttle_counter
end

Class Method Details

.report_exception(e) ⇒ Object



10
11
12
# File 'lib/safely/core.rb', line 10

def report_exception(e)
  report_exception_method.call(e)
end

.throttled?(e, options) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
21
22
23
# File 'lib/safely/core.rb', line 18

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