Add valid_plugin_name? predicate and push exclusion list check into its own method

Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
This commit is contained in:
Clinton Wolfe 2019-08-15 17:31:24 -04:00
parent 16fecbefb5
commit 3cd6eee016
2 changed files with 13 additions and 4 deletions

View file

@ -63,11 +63,19 @@ module Inspec::Plugin::V2
module FilterPredicates
def train_plugin_name?(name)
name.to_s.start_with?("train-") && ! Inspec::Plugin::V2::PluginFilter.exclude?(name)
name.to_s.start_with?("train-") && name_allowed?(name)
end
def inspec_plugin_name?(name)
name.to_s.start_with?("inspec-") && ! Inspec::Plugin::V2::PluginFilter.exclude?(name)
name.to_s.start_with?("inspec-") && name_allowed?(name)
end
def valid_plugin_name?(name)
name.to_s.match(/^(inspec|train)-/) && name_allowed?(name)
end
def name_allowed?(name)
! Inspec::Plugin::V2::PluginFilter.exclude?(name)
end
end
end

View file

@ -137,10 +137,11 @@ module Inspec::Plugin::V2
end
# Lists all plugin gems found in the plugin_gem_path.
# This is simply all gems that begin with train- or inspec-.
# This is simply all gems that begin with train- or inspec-
# and are not on the exclusion list.
# @return [Array[Gem::Specification]] Specs of all gems found.
def self.list_installed_plugin_gems
list_managed_gems.select { |spec| inspec_plugin_name?(spec.name) || train_plugin_name?(spec.name) }
list_managed_gems.select { |spec| valid_plugin_name?(spec.name) }
end
def list_installed_plugin_gems