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.



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

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

Instance Attribute Details

#callablesObject (readonly)

Returns the value of attribute callables.



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

def callables
  @callables
end

#dependenciesObject (readonly)

Returns the value of attribute dependencies.



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

def dependencies
  @dependencies
end

#loadedObject

Returns the value of attribute loaded.



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

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

#on_demandObject

Returns the value of attribute on_demand.



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

def on_demand
  @on_demand
end

#revert_callablesObject (readonly)

Returns the value of attribute revert_callables.



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

def revert_callables
  @revert_callables
end

Instance Method Details

#configurationObject



25
26
27
# File 'lib/rollbar/plugin.rb', line 25

def configuration
  Rollbar.configuration
end

#execute(&block) ⇒ Object



73
74
75
# File 'lib/rollbar/plugin.rb', line 73

def execute(&block)
  callables << block
end

#execute!Object



77
78
79
# File 'lib/rollbar/plugin.rb', line 77

def execute!
  yield if load?
end

#load!Object



49
50
51
52
53
54
55
56
57
58
59
# 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

#load_on_demandObject



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

def load_on_demand
  @on_demand = true
end

#load_scoped!(transparent = false) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# 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

#revert(&block) ⇒ Object



81
82
83
# File 'lib/rollbar/plugin.rb', line 81

def revert(&block)
  revert_callables << block
end

#unload!Object



61
62
63
64
65
66
67
68
69
70
71
# 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