Class: Necropsy::Configuration
- Inherits:
-
Object
- Object
- Necropsy::Configuration
- Defined in:
- lib/necropsy/configuration.rb
Constant Summary collapse
- DEFAULT_FAIL_ON =
:high- DEFAULT_BASELINE =
'.necropsy_baseline.yml'
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Class Method Summary collapse
Instance Method Summary collapse
- #baseline_path ⇒ Object
- #bench_precision_threshold ⇒ Object
- #bench_recall_threshold ⇒ Object
- #cache_enabled? ⇒ Boolean
- #cache_path ⇒ Object
- #custom_analyzers ⇒ Object
- #dynamic_config(name) ⇒ Object
- #entry_point_patterns ⇒ Object
- #factory_methods ⇒ Object
- #fail_on ⇒ Object
- #frameworks ⇒ Object
-
#initialize(root:, path:, data:) ⇒ Configuration
constructor
A new instance of Configuration.
- #min_observation_days ⇒ Object
- #quarantine_days ⇒ Object
- #rails_enabled? ⇒ Boolean
- #scan_cache_key ⇒ Object
- #static_analyzers ⇒ Object
Constructor Details
#initialize(root:, path:, data:) ⇒ Configuration
Returns a new instance of Configuration.
18 19 20 21 22 |
# File 'lib/necropsy/configuration.rb', line 18 def initialize(root:, path:, data:) @root = File.(root) @path = path @data = stringify_keys(data) end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
10 11 12 |
# File 'lib/necropsy/configuration.rb', line 10 def data @data end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
10 11 12 |
# File 'lib/necropsy/configuration.rb', line 10 def path @path end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
10 11 12 |
# File 'lib/necropsy/configuration.rb', line 10 def root @root end |
Class Method Details
.load(root:, path: nil) ⇒ Object
12 13 14 15 16 |
# File 'lib/necropsy/configuration.rb', line 12 def self.load(root:, path: nil) config_path = path ? File.(path, root) : File.join(root, '.necropsy.yml') data = File.exist?(config_path) ? YAML.load_file(config_path) : {} new(root: root, path: config_path, data: data || {}) end |
Instance Method Details
#baseline_path ⇒ Object
51 52 53 |
# File 'lib/necropsy/configuration.rb', line 51 def baseline_path fetch('ci', 'baseline') || DEFAULT_BASELINE end |
#bench_precision_threshold ⇒ Object
69 70 71 |
# File 'lib/necropsy/configuration.rb', line 69 def bench_precision_threshold (fetch('bench', 'precision_threshold') || 0.85).to_f end |
#bench_recall_threshold ⇒ Object
73 74 75 76 |
# File 'lib/necropsy/configuration.rb', line 73 def bench_recall_threshold value = fetch('bench', 'recall_threshold') value&.to_f end |
#cache_enabled? ⇒ Boolean
78 79 80 81 |
# File 'lib/necropsy/configuration.rb', line 78 def cache_enabled? value = fetch('cache', 'enabled') value.nil? || value != false end |
#cache_path ⇒ Object
83 84 85 |
# File 'lib/necropsy/configuration.rb', line 83 def cache_path fetch('cache', 'path') || '.necropsy_cache/scan.yml' end |
#custom_analyzers ⇒ Object
32 33 34 |
# File 'lib/necropsy/configuration.rb', line 32 def custom_analyzers Array(fetch('analyzers', 'custom')).compact end |
#dynamic_config(name) ⇒ Object
28 29 30 |
# File 'lib/necropsy/configuration.rb', line 28 def dynamic_config(name) fetch('analyzers', 'dynamic', name.to_s) || {} end |
#entry_point_patterns ⇒ Object
36 37 38 |
# File 'lib/necropsy/configuration.rb', line 36 def entry_point_patterns Array(fetch('entry_points', 'extra')).compact.map(&:to_s) end |
#factory_methods ⇒ Object
91 92 93 |
# File 'lib/necropsy/configuration.rb', line 91 def factory_methods Array(fetch('rta', 'factory_methods') || %w[build create build_stubbed]).map(&:to_s) end |
#fail_on ⇒ Object
55 56 57 |
# File 'lib/necropsy/configuration.rb', line 55 def fail_on (fetch('ci', 'fail_on') || DEFAULT_FAIL_ON).to_sym end |
#frameworks ⇒ Object
40 41 42 |
# File 'lib/necropsy/configuration.rb', line 40 def frameworks Array(data['frameworks']).map(&:to_s) end |
#min_observation_days ⇒ Object
59 60 61 62 63 |
# File 'lib/necropsy/configuration.rb', line 59 def min_observation_days coverage_days = fetch('analyzers', 'dynamic', 'coverage', 'min_observation_days') coverband_days = fetch('analyzers', 'dynamic', 'coverband', 'min_observation_days') (coverage_days || coverband_days || 30).to_i end |
#quarantine_days ⇒ Object
65 66 67 |
# File 'lib/necropsy/configuration.rb', line 65 def quarantine_days (fetch('quarantine', 'days') || 30).to_i end |
#rails_enabled? ⇒ Boolean
44 45 46 47 48 49 |
# File 'lib/necropsy/configuration.rb', line 44 def rails_enabled? return true if frameworks.include?('rails') gemfiles = [File.join(root, 'Gemfile.lock'), File.join(root, 'Gemfile')] gemfiles.any? { |file| File.exist?(file) && File.read(file).match?(/(?:^|\s)rails(?:\s|\z|,)/) } end |
#scan_cache_key ⇒ Object
87 88 89 |
# File 'lib/necropsy/configuration.rb', line 87 def scan_cache_key data.except('cache') end |
#static_analyzers ⇒ Object
24 25 26 |
# File 'lib/necropsy/configuration.rb', line 24 def static_analyzers Array(fetch('analyzers', 'static') || %w[name_resolution cha rta]).map(&:to_s) end |