Class: Rollbar::Plugin

Inherits:
Object
  • Object
show all
Defined in:
lib/rollbar/plugin.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Plugin

Returns a new instance of Plugin.



14
15
16
17
18
19
# File 'lib/rollbar/plugin.rb', line 14

def initialize(name)
  @name = name
  @dependencies = []
  @callables = []
  @loaded = false
end

Instance Attribute Details

#callablesObject (readonly)

Returns the value of attribute callables.



9
10
11
# File 'lib/rollbar/plugin.rb', line 9

def callables
  @callables
end

#dependenciesObject (readonly)

Returns the value of attribute dependencies.



8
9
10
# File 'lib/rollbar/plugin.rb', line 8

def dependencies
  @dependencies
end

#loadedObject

Returns the value of attribute loaded.



10
11
12
# File 'lib/rollbar/plugin.rb', line 10

def loaded
  @loaded
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/rollbar/plugin.rb', line 7

def name
  @name
end

Instance Method Details

#configurationObject



21
22
23
# File 'lib/rollbar/plugin.rb', line 21

def configuration
  Rollbar.configuration
end

#execute(&block) ⇒ Object



37
38
39
# File 'lib/rollbar/plugin.rb', line 37

def execute(&block)
  callables << block
end

#execute!(&block) ⇒ Object



41
42
43
# File 'lib/rollbar/plugin.rb', line 41

def execute!(&block)
  block.call if load?
end

#load!Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rollbar/plugin.rb', line 25

def load!
  return unless load?

  begin
    callables.each(&:call)
  rescue => e
    log_loading_error(e)
  ensure
    self.loaded = true
  end
end