mirror of
https://github.com/inspec/inspec
synced 2024-11-14 17:07:09 +00:00
Refactored V2::Activator into more idiomatic ruby.
Predicate methods are usually added to make code more expressive, but they still act off of normal attributes. Predicate methods are not setters. This moves from X? to X and then aliases the predicate method. Signed-off-by: Ryan Davis <zenspider@chef.io>
This commit is contained in:
parent
de22ba3ac1
commit
4e822f3c37
2 changed files with 5 additions and 9 deletions
|
@ -3,21 +3,17 @@ module Inspec::Plugin::V2
|
|||
:plugin_name,
|
||||
:plugin_type,
|
||||
:activator_name,
|
||||
:activated?,
|
||||
:activated,
|
||||
:exception,
|
||||
:activation_proc,
|
||||
:implementation_class
|
||||
) do
|
||||
def initialize(*)
|
||||
super
|
||||
self[:'activated?'] = false
|
||||
self[:activated] = false
|
||||
end
|
||||
|
||||
def activated?(new_value = nil)
|
||||
return self[:activated?] if new_value.nil?
|
||||
|
||||
self[:activated?] = new_value
|
||||
end
|
||||
alias activated? activated
|
||||
|
||||
# Load a plugin, but if an error is encountered, store it and continue
|
||||
def activate
|
||||
|
@ -26,7 +22,7 @@ module Inspec::Plugin::V2
|
|||
# rubocop: disable Lint/RescueException
|
||||
begin
|
||||
impl_class = self[:activation_proc].call
|
||||
self[:activated?] = true
|
||||
self.activated = true
|
||||
self[:implementation_class] = impl_class
|
||||
rescue Exception => ex
|
||||
self[:exception] = ex
|
||||
|
|
|
@ -201,7 +201,7 @@ module Inspec::Plugin::V2
|
|||
status = registry[plugin_name]
|
||||
status.api_generation = 0
|
||||
act = Activator.new
|
||||
act.activated?(true)
|
||||
act.activated = true
|
||||
act.plugin_type = :cli_command
|
||||
act.plugin_name = plugin_name
|
||||
act.activator_name = :default
|
||||
|
|
Loading…
Reference in a new issue