Class: Bundler::Audit::Fix::Configuration
- Inherits:
-
Configuration
- Object
- Configuration
- Bundler::Audit::Fix::Configuration
- Defined in:
- lib/bundler/audit/fix/configuration.rb
Overview
Class for configurations.
Instance Attribute Summary collapse
-
#replacements ⇒ Object
Returns the value of attribute replacements.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(config = {}) ⇒ Configuration
constructor
A new instance of Configuration.
Constructor Details
#initialize(config = {}) ⇒ Configuration
Returns a new instance of Configuration.
69 70 71 72 |
# File 'lib/bundler/audit/fix/configuration.rb', line 69 def initialize(config = {}) super(config) load_default end |
Instance Attribute Details
#replacements ⇒ Object
Returns the value of attribute replacements.
30 31 32 |
# File 'lib/bundler/audit/fix/configuration.rb', line 30 def replacements @replacements end |
Class Method Details
.build_replacements(params) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/bundler/audit/fix/configuration.rb', line 52 def build_replacements(params) params.children.each_slice(2).map do |key, value| unless value.children raise(InvalidConfigurationError, "'replacement.#{key.value}' in config file is empty") end unless value.children.all? { |node| node.is_a?(YAML::Nodes::Scalar) } raise(InvalidConfigurationError, "'replacement.#{key.value}' array in config file contains a non-String") end { key.value => value.children.map(&:value) } end.inject(&:merge) end |
.load(file_path) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/bundler/audit/fix/configuration.rb', line 33 def load(file_path) instance = super(file_path) doc = YAML.parse(File.new(file_path)) doc.root.children.each_slice(2) do |key, value| case key.value when 'replacement' unless value.children.is_a?(Array) raise(InvalidConfigurationError, "'replacement' key found in config file, but is not an Array") end instance.replacements ||= {} instance.replacements = instance.replacements.merge(build_replacements(value)) end end instance end |