Class: Honeybadger::Plugin Private

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

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Defined Under Namespace

Classes: Execution

Constant Summary collapse

CALLER_FILE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Regexp.new('\A(?:\w:)?([^:]+)(?=(:\d+))').freeze
@@instances =

This classvariable is part of a private API. You should avoid using this classvariable if possible, as it may be removed or be changed in the future.

{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Plugin

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Plugin


57
58
59
60
61
62
# File 'lib/honeybadger/plugin.rb', line 57

def initialize(name)
  @name         = name
  @loaded       = false
  @requirements = []
  @executions   = []
end

Instance Attribute Details

#executionsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


108
109
110
# File 'lib/honeybadger/plugin.rb', line 108

def executions
  @executions
end

#nameObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


108
109
110
# File 'lib/honeybadger/plugin.rb', line 108

def name
  @name
end

#requirementsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


108
109
110
# File 'lib/honeybadger/plugin.rb', line 108

def requirements
  @requirements
end

Class Method Details

.instancesObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


11
12
13
# File 'lib/honeybadger/plugin.rb', line 11

def instances
  @@instances
end

.load!(config) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


22
23
24
25
26
27
28
29
30
# File 'lib/honeybadger/plugin.rb', line 22

def load!(config)
  instances.each_pair do |name, plugin|
    if config.load_plugin?(name)
      plugin.load!(config)
    else
      config.logger.debug(sprintf('skip plugin name=%s reason=disabled', name))
    end
  end
end

.name_from_caller(caller) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


32
33
34
35
36
# File 'lib/honeybadger/plugin.rb', line 32

def name_from_caller(caller)
  caller && caller[0].match(CALLER_FILE) or
    fail("Unable to determine name from caller: #{caller.inspect}")
  File.basename($1)[/[^\.]+/]
end

.register(name = nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


15
16
17
18
19
20
# File 'lib/honeybadger/plugin.rb', line 15

def register(name = nil)
  name ||= name_from_caller(caller) or
    raise(ArgumentError, 'Plugin name is required, but was nil.')
  instances[key = name.to_sym] and fail("Already registered: #{name}")
  instances[key] = new(name).tap { |d| d.instance_eval(&Proc.new) }
end

Instance Method Details

#executionObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


68
69
70
# File 'lib/honeybadger/plugin.rb', line 68

def execution
  @executions << Proc.new
end

#load!(config) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/honeybadger/plugin.rb', line 79

def load!(config)
  if @loaded
    config.logger.debug(sprintf('skip plugin name=%s reason=loaded', name))
    return false
  elsif ok?(config)
    config.logger.debug(sprintf('load plugin name=%s', name))
    @executions.each {|e| Execution.new(config, &e).call }
    @loaded = true
  else
    config.logger.debug(sprintf('skip plugin name=%s reason=requirement', name))
  end

  @loaded
rescue => e
  config.logger.error(sprintf("plugin error name=%s class=%s message=%s\n\t%s", name, e.class, e.message.dump, Array(e.backtrace).join("\n\t")))
  @loaded = true
  false
end

#loaded?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)

104
105
106
# File 'lib/honeybadger/plugin.rb', line 104

def loaded?
  @loaded
end

#ok?(config) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)

72
73
74
75
76
77
# File 'lib/honeybadger/plugin.rb', line 72

def ok?(config)
  @requirements.all? {|r| Execution.new(config, &r).call }
rescue => e
  config.logger.error(sprintf("plugin error name=%s class=%s message=%s\n\t%s", name, e.class, e.message.dump, Array(e.backtrace).join("\n\t")))
  false
end

#requirementObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


64
65
66
# File 'lib/honeybadger/plugin.rb', line 64

def requirement
  @requirements << Proc.new
end