Class: Flydata::RollbarHookSetup
- Inherits:
-
Object
- Object
- Flydata::RollbarHookSetup
- Defined in:
- lib/flydata/error_reporting.rb
Instance Method Summary collapse
- #already_setup? ⇒ Boolean
- #config_available? ⇒ Boolean
-
#initialize(log, access_token = ENV['ROLLBAR_ACCESS_TOKEN'], environment = ENV['ROLLBAR_ENV']) ⇒ RollbarHookSetup
constructor
A new instance of RollbarHookSetup.
- #rollbar_configure ⇒ Object
- #rollbar_flag? ⇒ Boolean
-
#rollbar_gem_name ⇒ Object
Use to stub in tests.
- #rollbar_installed? ⇒ Boolean
- #setup ⇒ Object
- #should_setup? ⇒ Boolean
Constructor Details
#initialize(log, access_token = ENV['ROLLBAR_ACCESS_TOKEN'], environment = ENV['ROLLBAR_ENV']) ⇒ RollbarHookSetup
Returns a new instance of RollbarHookSetup.
7 8 9 10 11 12 13 |
# File 'lib/flydata/error_reporting.rb', line 7 def initialize(log, access_token=ENV['ROLLBAR_ACCESS_TOKEN'], environment=ENV['ROLLBAR_ENV']) @log = log @access_token = access_token @environment = environment end |
Instance Method Details
#already_setup? ⇒ Boolean
32 33 34 |
# File 'lib/flydata/error_reporting.rb', line 32 def already_setup? @log.instance_variable_defined?('@_rollbar_hook_enabled') end |
#config_available? ⇒ Boolean
23 24 25 26 27 28 29 30 |
# File 'lib/flydata/error_reporting.rb', line 23 def config_available? return false unless @access_token return false if @access_token.empty? return false unless @environment return false if @environment.empty? true end |
#rollbar_configure ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/flydata/error_reporting.rb', line 49 def return unless require Rollbar.configure do |config| # Only actually send rollbar errors to endpoint in production and staging. config.enabled = ['production', 'staging'].include?(@environment) config.access_token = @access_token config.environment = @environment || 'development' config.custom_data_method = lambda do |, exception, context| { flydata_home: FLYDATA_HOME } end end end |
#rollbar_flag? ⇒ Boolean
19 20 21 |
# File 'lib/flydata/error_reporting.rb', line 19 def File.exists?(File.join(FLYDATA_HOME, 'use_rollbar')) end |
#rollbar_gem_name ⇒ Object
Use to stub in tests
37 38 39 |
# File 'lib/flydata/error_reporting.rb', line 37 def 'rollbar' end |
#rollbar_installed? ⇒ Boolean
41 42 43 44 45 46 47 |
# File 'lib/flydata/error_reporting.rb', line 41 def if Gem::Specification.respond_to?(:find_all_by_name) Gem::Specification.find_all_by_name().any? else Gem.source_index.find_name().first end end |
#setup ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/flydata/error_reporting.rb', line 65 def setup return false unless should_setup? old_error = @log.method(:error) # Replace the existing logger's error method so that it will report to rollbar messages or exceptions # when .error is called. @log.define_singleton_method :error do |*args| old_error.call(*args) if $!.nil? Rollbar.error(args.first) # Just the message portion else Rollbar.error($!) # Send the exception details end end # Make this method idempotent: future calls will have no effect now. @log.instance_variable_set('@_rollbar_hook_enabled', true) true end |
#should_setup? ⇒ Boolean
15 16 17 |
# File 'lib/flydata/error_reporting.rb', line 15 def should_setup? (!already_setup?) && && && config_available? end |