Class: MonkeyLens::Config
- Inherits:
-
Object
- Object
- MonkeyLens::Config
- Defined in:
- lib/monkey_lens/config.rb,
sig/monkey_lens.rbs
Constant Summary collapse
- LEVELS =
%w[low medium high critical].freeze
- FORMATS =
%w[text json sarif].freeze
Instance Attribute Summary collapse
-
#baseline ⇒ String
readonly
Returns the value of attribute baseline.
-
#fail_on ⇒ String
readonly
Returns the value of attribute fail_on.
-
#format ⇒ String
readonly
Returns the value of attribute format.
-
#ignore_methods ⇒ Array[String]
readonly
Returns the value of attribute ignore_methods.
-
#requires ⇒ Array[String]
readonly
Returns the value of attribute requires.
-
#targets ⇒ Array[String]
readonly
Returns the value of attribute targets.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(targets:, ignore_methods: [], fail_on: "high", format: "text", baseline: ".monkeylens.json", requires: []) ⇒ Config
constructor
A new instance of Config.
Constructor Details
#initialize(targets:, ignore_methods: [], fail_on: "high", format: "text", baseline: ".monkeylens.json", requires: []) ⇒ Config
Returns a new instance of Config.
12 13 14 15 16 17 18 19 20 |
# File 'lib/monkey_lens/config.rb', line 12 def initialize(targets:, ignore_methods: [], fail_on: "high", format: "text", baseline: ".monkeylens.json", requires: []) @targets = Array(targets).map(&:to_s).uniq @ignore_methods = Array(ignore_methods).map(&:to_s).uniq @fail_on = fail_on.to_s @format = format.to_s @baseline = baseline.to_s @requires = Array(requires).map(&:to_s) validate! end |
Instance Attribute Details
#baseline ⇒ String (readonly)
Returns the value of attribute baseline.
10 11 12 |
# File 'lib/monkey_lens/config.rb', line 10 def baseline @baseline end |
#fail_on ⇒ String (readonly)
Returns the value of attribute fail_on.
10 11 12 |
# File 'lib/monkey_lens/config.rb', line 10 def fail_on @fail_on end |
#format ⇒ String (readonly)
Returns the value of attribute format.
10 11 12 |
# File 'lib/monkey_lens/config.rb', line 10 def format @format end |
#ignore_methods ⇒ Array[String] (readonly)
Returns the value of attribute ignore_methods.
10 11 12 |
# File 'lib/monkey_lens/config.rb', line 10 def ignore_methods @ignore_methods end |
#requires ⇒ Array[String] (readonly)
Returns the value of attribute requires.
10 11 12 |
# File 'lib/monkey_lens/config.rb', line 10 def requires @requires end |
#targets ⇒ Array[String] (readonly)
Returns the value of attribute targets.
10 11 12 |
# File 'lib/monkey_lens/config.rb', line 10 def targets @targets end |
Class Method Details
.load(path = ".monkeylens.yml") ⇒ Config
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/monkey_lens/config.rb', line 22 def self.load(path = ".monkeylens.yml") data = File.exist?(path) ? YAML.safe_load_file(path, permitted_classes: [], aliases: false) : {} data ||= {} new( targets: data.fetch("targets", []), ignore_methods: data.fetch("ignore_methods", []), fail_on: data.fetch("fail_on", "high"), format: data.fetch("format", "text"), baseline: data.fetch("baseline", ".monkeylens.json"), requires: data.fetch("requires", []) ) rescue Psych::Exception => error raise ConfigurationError, "invalid YAML in #{path}: #{error.}" end |