Class: Bundler::Audit::Configuration
- Inherits:
-
Object
- Object
- Bundler::Audit::Configuration
- Defined in:
- lib/bundler/audit/configuration.rb
Overview
Class for storing and validating configuration for running the auditor.
Defined Under Namespace
Classes: FileNotFound, InvalidConfigurationError
Instance Attribute Summary collapse
-
#ignore ⇒ Set<String>
readonly
The list of advisory IDs to ignore.
Class Method Summary collapse
-
.load(file_path) ⇒ Configuration
A constructor method for loading configuration from a YAML file.
Instance Method Summary collapse
-
#initialize(config = {}) ⇒ Configuration
constructor
Initializes the configuration.
Constructor Details
#initialize(config = {}) ⇒ Configuration
Initializes the configuration.
102 103 104 |
# File 'lib/bundler/audit/configuration.rb', line 102 def initialize(config={}) @ignore = Set.new(config[:ignore]) end |
Instance Attribute Details
#ignore ⇒ Set<String> (readonly)
The list of advisory IDs to ignore.
91 92 93 |
# File 'lib/bundler/audit/configuration.rb', line 91 def ignore @ignore end |
Class Method Details
.load(file_path) ⇒ Configuration
A constructor method for loading configuration from a YAML file.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# 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 |