Sha256: 2dc9b2df6b1490344859450763d2d988c07934c4a2fa7661190842359548c34b

Contents?: true

Size: 1.1 KB

Versions: 20

Compression:

Stored size: 1.1 KB

Contents

module Inspec::Plugin::V2
  Activator = Struct.new(
    :plugin_name,
    :plugin_type,
    :activator_name,
    :activated?,
    :exception,
    :activation_proc,
    :implementation_class,
  ) do
    def initialize(*)
      super
      self[:'activated?'] = false
    end

    def activated?(new_value = nil)
      return self[:activated?] if new_value.nil?
      self[:activated?] = new_value
    end

    # Load a plugin, but if an error is encountered, store it and continue
    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

    # Load a plugin, but if an error is encountered, re-throw it
    def activate!
      activate
      raise exception if exception
    end
  end
end

Version data entries

20 entries across 20 versions & 2 rubygems

Version Path
inspec-core-4.3.2 lib/inspec/plugin/v2/activator.rb
inspec-4.3.2 lib/inspec/plugin/v2/activator.rb
inspec-core-4.2.0.preview lib/inspec/plugin/v2/activator.rb
inspec-4.2.0.preview lib/inspec/plugin/v2/activator.rb
inspec-core-4.1.4.preview lib/inspec/plugin/v2/activator.rb
inspec-4.1.4.preview lib/inspec/plugin/v2/activator.rb
inspec-core-3.9.3 lib/inspec/plugin/v2/activator.rb
inspec-3.9.3 lib/inspec/plugin/v2/activator.rb
inspec-core-3.9.0 lib/inspec/plugin/v2/activator.rb
inspec-3.9.0 lib/inspec/plugin/v2/activator.rb
inspec-core-3.7.11 lib/inspec/plugin/v2/activator.rb
inspec-3.7.11 lib/inspec/plugin/v2/activator.rb
inspec-core-3.7.1 lib/inspec/plugin/v2/activator.rb
inspec-3.7.1 lib/inspec/plugin/v2/activator.rb
inspec-core-3.6.6 lib/inspec/plugin/v2/activator.rb
inspec-3.6.6 lib/inspec/plugin/v2/activator.rb
inspec-core-3.6.4 lib/inspec/plugin/v2/activator.rb
inspec-3.6.4 lib/inspec/plugin/v2/activator.rb
inspec-core-3.6.2 lib/inspec/plugin/v2/activator.rb
inspec-3.6.2 lib/inspec/plugin/v2/activator.rb