lib/immunio/plugin.rb in immunio-1.1.6 vs lib/immunio/plugin.rb in immunio-1.1.7
- old
+ new
@@ -12,15 +12,17 @@
#
# Each registered plugin is reported to the backend via the `EnvironmentReporter`.
class Plugin
attr_reader :status
attr_accessor :version
+ attr_accessor :hooks
- def initialize(name)
+ def initialize(name, hooks = [])
@name = name
@status = 'pending'
@version = nil
+ @hooks = hooks
end
def loaded!(version)
@status = 'loaded'
@version = version
@@ -36,18 +38,19 @@
@status = 'failed'
Immunio.logger.error "Plugin #{@name} failed to load: #{error}"
end
def inspect
- "<#{self.class} name=#{@name.inspect} status=#{@status.inspect} version=#{@version.inspect}>"
+ "<#{self.class} name=#{@name.inspect} status=#{@status.inspect} version=#{@version.inspect} hooks=#{@hooks.inspect}>"
end
def to_msgpack(packer)
- packer.write_map_header 2
+ packer.write_map_header 3
# `name` is provided as the key in `registered`
packer.write('status').write(@status)
packer.write('version').write(@version)
+ packer.write('hooks').write(@hooks)
end
def self.registered
@registered ||= {}
end
@@ -74,11 +77,11 @@
enabled = Immunio.agent.plugin_enabled?(options[:feature])
else
enabled = true
end
- plugin = registered[name] = new(name)
+ plugin = registered[name] = new(name, options.fetch(:hooks, []))
unless enabled # plugin is disabled
plugin.disabled!
return
end
@@ -89,6 +92,6 @@
rescue StandardError, LoadError => e
plugin.failed! e
end
end
end
-end
\ No newline at end of file
+end