Class: Inspec::Plugin::V2::Activator

Inherits:
Struct
  • Object
show all
Defined in:
lib/inspec/plugin/v2/activator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeActivator

Returns a new instance of Activator.



11
12
13
14
# File 'lib/inspec/plugin/v2/activator.rb', line 11

def initialize(*)
  super
  self[:activated] = false
end

Instance Attribute Details

#activatedObject Also known as: activated?

Returns the value of attribute activated

Returns:

  • (Object)

    the current value of activated



2
3
4
# File 'lib/inspec/plugin/v2/activator.rb', line 2

def activated
  @activated
end

#activation_procObject

Returns the value of attribute activation_proc

Returns:

  • (Object)

    the current value of activation_proc



2
3
4
# File 'lib/inspec/plugin/v2/activator.rb', line 2

def activation_proc
  @activation_proc
end

#activator_nameObject

Returns the value of attribute activator_name

Returns:

  • (Object)

    the current value of activator_name



2
3
4
# File 'lib/inspec/plugin/v2/activator.rb', line 2

def activator_name
  @activator_name
end

#exceptionObject

Returns the value of attribute exception

Returns:

  • (Object)

    the current value of exception



2
3
4
# File 'lib/inspec/plugin/v2/activator.rb', line 2

def exception
  @exception
end

#implementation_classObject

Returns the value of attribute implementation_class

Returns:

  • (Object)

    the current value of implementation_class



2
3
4
# File 'lib/inspec/plugin/v2/activator.rb', line 2

def implementation_class
  @implementation_class
end

#plugin_nameObject

Returns the value of attribute plugin_name

Returns:

  • (Object)

    the current value of plugin_name



2
3
4
# File 'lib/inspec/plugin/v2/activator.rb', line 2

def plugin_name
  @plugin_name
end

#plugin_typeObject

Returns the value of attribute plugin_type

Returns:

  • (Object)

    the current value of plugin_type



2
3
4
# File 'lib/inspec/plugin/v2/activator.rb', line 2

def plugin_type
  @plugin_type
end

Instance Method Details

#activateObject

Load a plugin, but if an error is encountered, store it and continue



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/inspec/plugin/v2/activator.rb', line 19

def activate
  return if activated?

  # rubocop: disable Lint/RescueException
  begin
    impl_class = self[:activation_proc].call
    self.activated = true
    self[:implementation_class] = impl_class
  rescue Exception => ex
    self[:exception] = ex
    Inspec::Log.error "Could not activate #{self[:plugin_type]} hook named '#{self[:activator_name]}' for plugin #{self[:plugin_name]}"
  end
  # rubocop: enable Lint/RescueException
end

#activate!Object

Load a plugin, but if an error is encountered, re-throw it



35
36
37
38
# File 'lib/inspec/plugin/v2/activator.rb', line 35

def activate!
  activate
  raise exception if exception
end