Class: RailVerdict::Intelligence::Budget
- Inherits:
-
Object
- Object
- RailVerdict::Intelligence::Budget
- Defined in:
- lib/rail_verdict/intelligence/budget.rb
Constant Summary collapse
- DEFAULTS =
{ max_findings: 3, max_requests: 3, max_context_bytes: 64 * 1024 }.freeze
Instance Attribute Summary collapse
-
#max_context_bytes ⇒ Object
readonly
Returns the value of attribute max_context_bytes.
-
#max_findings ⇒ Object
readonly
Returns the value of attribute max_findings.
-
#max_requests ⇒ Object
readonly
Returns the value of attribute max_requests.
Class Method Summary collapse
Instance Method Summary collapse
- #enforce!(manifest) ⇒ Object
-
#initialize(config_budgets = {}) ⇒ Budget
constructor
A new instance of Budget.
Constructor Details
#initialize(config_budgets = {}) ⇒ Budget
Returns a new instance of Budget.
14 15 16 17 18 |
# File 'lib/rail_verdict/intelligence/budget.rb', line 14 def initialize(config_budgets = {}) @max_findings = (config_budgets["max_findings"] || DEFAULTS[:max_findings]).to_i @max_requests = (config_budgets["max_requests"] || DEFAULTS[:max_requests]).to_i @max_context_bytes = (config_budgets["max_context_bytes"] || DEFAULTS[:max_context_bytes]).to_i end |
Instance Attribute Details
#max_context_bytes ⇒ Object (readonly)
Returns the value of attribute max_context_bytes.
12 13 14 |
# File 'lib/rail_verdict/intelligence/budget.rb', line 12 def max_context_bytes @max_context_bytes end |
#max_findings ⇒ Object (readonly)
Returns the value of attribute max_findings.
12 13 14 |
# File 'lib/rail_verdict/intelligence/budget.rb', line 12 def max_findings @max_findings end |
#max_requests ⇒ Object (readonly)
Returns the value of attribute max_requests.
12 13 14 |
# File 'lib/rail_verdict/intelligence/budget.rb', line 12 def max_requests @max_requests end |
Class Method Details
.select_findings(findings, limit:) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/rail_verdict/intelligence/budget.rb', line 26 def self.select_findings(findings, limit:) severity_rank = { "critical" => 0, "high" => 1, "medium" => 2, "low" => 3, "info" => 4 } findings.sort_by do |f| blocking = f.respond_to?(:state) ? (f.state == "introduced" ? 0 : 1) : 1 sev = severity_rank[f.severity] || 5 [blocking, sev, f.sort_key] end.first(limit) end |