Class: Contracts::MutationReport
- Inherits:
-
Object
- Object
- Contracts::MutationReport
- Defined in:
- lib/contracts.rb
Instance Attribute Summary collapse
-
#after_values ⇒ Object
readonly
Returns the value of attribute after_values.
-
#before_values ⇒ Object
readonly
Returns the value of attribute before_values.
-
#changed_fields ⇒ Object
readonly
Returns the value of attribute changed_fields.
-
#missing_required_changes ⇒ Object
readonly
Returns the value of attribute missing_required_changes.
-
#permitted_changes ⇒ Object
readonly
Returns the value of attribute permitted_changes.
-
#unchanged_fields ⇒ Object
readonly
Returns the value of attribute unchanged_fields.
-
#unexpected_changes ⇒ Object
readonly
Returns the value of attribute unexpected_changes.
Instance Method Summary collapse
-
#initialize(before:, after:, permitted:, required:, observations:) ⇒ MutationReport
constructor
A new instance of MutationReport.
- #passed? ⇒ Boolean
- #to_h ⇒ Object
Constructor Details
#initialize(before:, after:, permitted:, required:, observations:) ⇒ MutationReport
Returns a new instance of MutationReport.
181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/contracts.rb', line 181 def initialize(before:, after:, permitted:, required:, observations:) @before_values = before.to_h.freeze @after_values = after.to_h.freeze @permitted_changes = permitted.freeze fields = @before_values.keys | @after_values.keys @changed_fields = fields.reject do |field| Contracts.equal_state?(@before_values[field], @after_values[field], observations[field]&.compare_with) end.freeze @unchanged_fields = (fields - @changed_fields).freeze @unexpected_changes = (@changed_fields - permitted).freeze @missing_required_changes = (required - @changed_fields).freeze end |
Instance Attribute Details
#after_values ⇒ Object (readonly)
Returns the value of attribute after_values.
178 179 180 |
# File 'lib/contracts.rb', line 178 def after_values @after_values end |
#before_values ⇒ Object (readonly)
Returns the value of attribute before_values.
178 179 180 |
# File 'lib/contracts.rb', line 178 def before_values @before_values end |
#changed_fields ⇒ Object (readonly)
Returns the value of attribute changed_fields.
178 179 180 |
# File 'lib/contracts.rb', line 178 def changed_fields @changed_fields end |
#missing_required_changes ⇒ Object (readonly)
Returns the value of attribute missing_required_changes.
178 179 180 |
# File 'lib/contracts.rb', line 178 def missing_required_changes @missing_required_changes end |
#permitted_changes ⇒ Object (readonly)
Returns the value of attribute permitted_changes.
178 179 180 |
# File 'lib/contracts.rb', line 178 def permitted_changes @permitted_changes end |
#unchanged_fields ⇒ Object (readonly)
Returns the value of attribute unchanged_fields.
178 179 180 |
# File 'lib/contracts.rb', line 178 def unchanged_fields @unchanged_fields end |
#unexpected_changes ⇒ Object (readonly)
Returns the value of attribute unexpected_changes.
178 179 180 |
# File 'lib/contracts.rb', line 178 def unexpected_changes @unexpected_changes end |
Instance Method Details
#passed? ⇒ Boolean
194 |
# File 'lib/contracts.rb', line 194 def passed? = unexpected_changes.empty? && missing_required_changes.empty? |
#to_h ⇒ Object
196 197 198 199 |
# File 'lib/contracts.rb', line 196 def to_h { passed: passed?, changed_fields: changed_fields, unchanged_fields: unchanged_fields, permitted_changes: permitted_changes, unexpected_changes: unexpected_changes, missing_required_changes: missing_required_changes, before_values: before_values, after_values: after_values } end |