Class: MonkeyLens::Policy::Decision
- Inherits:
-
Object
- Object
- MonkeyLens::Policy::Decision
- Defined in:
- lib/monkey_lens/policy.rb
Instance Attribute Summary collapse
-
#effective_changes ⇒ Object
readonly
Returns the value of attribute effective_changes.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
-
#threshold ⇒ Object
readonly
Returns the value of attribute threshold.
-
#waived_changes ⇒ Object
readonly
Returns the value of attribute waived_changes.
Instance Method Summary collapse
- #clean? ⇒ Boolean
- #failure? ⇒ Boolean
-
#initialize(result:, effective_changes:, waived_changes:, threshold:) ⇒ Decision
constructor
A new instance of Decision.
- #to_h ⇒ Object
Constructor Details
#initialize(result:, effective_changes:, waived_changes:, threshold:) ⇒ Decision
Returns a new instance of Decision.
55 56 57 58 59 60 |
# File 'lib/monkey_lens/policy.rb', line 55 def initialize(result:, effective_changes:, waived_changes:, threshold:) @result = result @effective_changes = effective_changes.freeze @waived_changes = waived_changes.freeze @threshold = threshold.to_s end |
Instance Attribute Details
#effective_changes ⇒ Object (readonly)
Returns the value of attribute effective_changes.
53 54 55 |
# File 'lib/monkey_lens/policy.rb', line 53 def effective_changes @effective_changes end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
53 54 55 |
# File 'lib/monkey_lens/policy.rb', line 53 def result @result end |
#threshold ⇒ Object (readonly)
Returns the value of attribute threshold.
53 54 55 |
# File 'lib/monkey_lens/policy.rb', line 53 def threshold @threshold end |
#waived_changes ⇒ Object (readonly)
Returns the value of attribute waived_changes.
53 54 55 |
# File 'lib/monkey_lens/policy.rb', line 53 def waived_changes @waived_changes end |
Instance Method Details
#clean? ⇒ Boolean
62 63 64 |
# File 'lib/monkey_lens/policy.rb', line 62 def clean? effective_changes.empty? end |
#failure? ⇒ Boolean
66 67 68 69 |
# File 'lib/monkey_lens/policy.rb', line 66 def failure? minimum = Change::LEVELS.fetch(threshold) effective_changes.any? { |change| change.level >= minimum } end |
#to_h ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/monkey_lens/policy.rb', line 71 def to_h { "schema" => 1, "clean" => clean?, "failure" => failure?, "threshold" => threshold, "summary" => Change::LEVELS.keys.to_h do |level| [level, effective_changes.count { |change| change.severity == level }] end, "effective_changes" => effective_changes.map(&:to_h), "waived_changes" => waived_changes.map do |item| {"change" => item.fetch(:change).to_h, "waiver" => item.fetch(:waiver).to_h} end } end |