Sha256: 244e80350582dcf2b1f4c5f53f50b4926762a4af71bbc7afb5a69f2f3a43b374
Contents?: true
Size: 1.43 KB
Versions: 26
Compression:
Stored size: 1.43 KB
Contents
module Rollbar # 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 class Plugin attr_reader :name attr_reader :dependencies attr_reader :callables attr_accessor :loaded private :loaded= def initialize(name) @name = name @dependencies = [] @callables = [] @loaded = false end def configuration Rollbar.configuration end def load! return unless load? begin callables.each(&:call) rescue => e log_loading_error(e) ensure self.loaded = true end end def execute(&block) callables << block end def execute!(&block) block.call if load? end private def dependency(&block) dependencies << block end def require_dependency(file) dependency do begin require file true rescue LoadError false end end end def load? !loaded && dependencies_satisfy? rescue => e log_loading_error(e) false end def dependencies_satisfy? dependencies.all?(&:call) end def log_loading_error(e) Rollbar.log_error("Error trying to load plugin '#{name}': #{e.class}, #{e.message}") end end end
Version data entries
26 entries across 26 versions & 1 rubygems