Class: MonkeyLens::Policy::Decision

Inherits:
Object
  • Object
show all
Defined in:
lib/monkey_lens/policy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_changesObject (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

#resultObject (readonly)

Returns the value of attribute result.



53
54
55
# File 'lib/monkey_lens/policy.rb', line 53

def result
  @result
end

#thresholdObject (readonly)

Returns the value of attribute threshold.



53
54
55
# File 'lib/monkey_lens/policy.rb', line 53

def threshold
  @threshold
end

#waived_changesObject (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

Returns:

  • (Boolean)


62
63
64
# File 'lib/monkey_lens/policy.rb', line 62

def clean?
  effective_changes.empty?
end

#failure?Boolean

Returns:

  • (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_hObject



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