class Bundler::Audit::Configuration
Class for storing and validating configuration for running the auditor.
@since 0.8.0
Attributes
ignore[R]
The list of advisory IDs to ignore.
@return [Set<String>]
Public Class Methods
load(file_path)
click to toggle source
A constructor method for loading configuration from a YAML file.
@param [String] file_path
Path to the YAML file holding the configuration.
@raise [FileNotFound]
Will raise a file not found error when the path to the configuration YAML file does not exist.
@raise [InvalidConfigurationError]
Will raise an invalid configuration error indicating what in the YAML file is invalid for the configuration.
@return [Configuration]
A Configuration object containing the config hash loaded from the file passed.
# File lib/bundler/audit/configuration.rb, line 53 def self.load(file_path) raise(FileNotFound,"Configuration file '#{file_path}' does not exist") unless File.exist?(file_path) doc = YAML.parse(File.new(file_path)) unless doc.kind_of?(YAML::Nodes::Document) raise(InvalidConfigurationError,"Configuration found in '#{file_path}' is not YAML") end unless doc.root.kind_of?(YAML::Nodes::Mapping) raise(InvalidConfigurationError,"Configuration found in '#{file_path}' is not a Hash") end config = {} doc.root.children.each_slice(2) do |key,value| case key.value when 'ignore' unless value.is_a?(YAML::Nodes::Sequence) raise(InvalidConfigurationError,"'ignore' key found in config file, but is not an Array") end unless value.children.all? { |node| node.is_a?(YAML::Nodes::Scalar) } raise(InvalidConfigurationError,"'ignore' array in config file contains a non-String") end config[:ignore] = value.children.map(&:value) end end new(config) end
new(config={})
click to toggle source
Initializes the configuration.
@param [Hash] config
The configuration hash.
@option config [Array<String>] :ignore
The list of advisory IDs to ignore.
# File lib/bundler/audit/configuration.rb, line 102 def initialize(config={}) @ignore = Set.new(config[:ignore]) end