class Rollbar::Plugin
Represents a plugin in the gem. Every plugin can have multiple dependencies and multiple execution blocks. On Rollbar
initialization, all plugins will be saved in memory and those that satisfy the dependencies will be loaded
Attributes
Public Class Methods
Source
# File lib/rollbar/plugin.rb, line 12 def initialize(name) @name = name @dependencies = [] @callables = [] @revert_callables = [] @loaded = false @on_demand = false end
Public Instance Methods
Source
# File lib/rollbar/plugin.rb, line 25 def configuration Rollbar.configuration end
Source
# File lib/rollbar/plugin.rb, line 73 def execute(&block) callables << block end
Source
# File lib/rollbar/plugin.rb, line 49 def load! return unless load? begin callables.each(&:call) rescue StandardError => e log_loading_error(e) ensure self.loaded = true end end
Source
# File lib/rollbar/plugin.rb, line 21 def load_on_demand @on_demand = true end
Source
# File lib/rollbar/plugin.rb, line 29 def load_scoped!(transparent = false) if transparent load! if load? result = yield unload! if loaded else return unless load? load! result = yield unload! end result end
Source
# File lib/rollbar/plugin.rb, line 81 def revert(&block) revert_callables << block end
Source
# File lib/rollbar/plugin.rb, line 61 def unload! return unless loaded begin revert_callables.each(&:call) rescue StandardError => e log_unloading_error(e) ensure self.loaded = false end end
Private Instance Methods
Source
# File lib/rollbar/plugin.rb, line 110 def dependencies_satisfy? dependencies.all?(&:call) end
Source
# File lib/rollbar/plugin.rb, line 87 def dependency(&block) dependencies << block end
Source
# File lib/rollbar/plugin.rb, line 102 def load? !loaded && dependencies_satisfy? rescue StandardError => e log_loading_error(e) false end
Source
# File lib/rollbar/plugin.rb, line 114 def log_loading_error(error) Rollbar.log_error( "Error trying to load plugin '#{name}': #{error.class}, #{error.message}" ) end
Source
# File lib/rollbar/plugin.rb, line 120 def log_unloading_error(error) Rollbar.log_error( "Error trying to unload plugin '#{name}': #{error.class}, #{error.message}" ) end
Source
# File lib/rollbar/plugin.rb, line 91 def require_dependency(file) dependency do begin require file true rescue LoadError false end end end