Class: ResourceCompareService

Inherits:
Object
  • Object
show all
Defined in:
app/services/resource_compare_service.rb

Overview

Compares two PDCMetadata::Resource objects and provides a hash with the ‘differences`

If there are no differences between the two objects ‘identical?` returns `true` and `differences == {}` If there are differences the `differences` hash has the following structure:

“‘

:field_name = [{action:, from: to:, value: }]

“‘

The array for “:field_name` lists all the changes that happened to the field. For single-value fields is always a single element array, for multi-value fields in can contain multiple elements.

The ‘action` indicates whether a value changed, was added, or deleted.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(before, after) ⇒ ResourceCompareService

Returns a new instance of ResourceCompareService.



21
22
23
24
25
26
# File 'app/services/resource_compare_service.rb', line 21

def initialize(before, after)
  @before = before
  @after = after
  @differences = {}
  compare_resources
end

Instance Attribute Details

#differencesObject (readonly)

Returns the value of attribute differences.



19
20
21
# File 'app/services/resource_compare_service.rb', line 19

def differences
  @differences
end

Instance Method Details

#identical?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'app/services/resource_compare_service.rb', line 28

def identical?
  @differences == {}
end