Class: Contracts::MutationReport

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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_valuesObject (readonly)

Returns the value of attribute after_values.



178
179
180
# File 'lib/contracts.rb', line 178

def after_values
  @after_values
end

#before_valuesObject (readonly)

Returns the value of attribute before_values.



178
179
180
# File 'lib/contracts.rb', line 178

def before_values
  @before_values
end

#changed_fieldsObject (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_changesObject (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_changesObject (readonly)

Returns the value of attribute permitted_changes.



178
179
180
# File 'lib/contracts.rb', line 178

def permitted_changes
  @permitted_changes
end

#unchanged_fieldsObject (readonly)

Returns the value of attribute unchanged_fields.



178
179
180
# File 'lib/contracts.rb', line 178

def unchanged_fields
  @unchanged_fields
end

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

Returns:

  • (Boolean)


194
# File 'lib/contracts.rb', line 194

def passed? = unexpected_changes.empty? && missing_required_changes.empty?

#to_hObject



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