Class: WorkCompareService

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(before, after) ⇒ WorkCompareService

Returns a new instance of WorkCompareService.



24
25
26
27
28
29
# File 'app/services/work_compare_service.rb', line 24

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

Instance Attribute Details

#differencesObject (readonly)

Returns the value of attribute differences.



4
5
6
# File 'app/services/work_compare_service.rb', line 4

def differences
  @differences
end

Class Method Details

.update_work(work:, update_params:, current_user:) ⇒ Boolean

Updates a work with the parameters and logs any changes

Parameters:

  • work (Work)

    work to be updated

  • update_params (HashWithIndifferentAccess)

    values to update the work with

  • []

    current_user user currently logged into the system

Returns:

  • (Boolean)

    true if update occured; false if update had errors



12
13
14
15
16
17
18
19
20
21
# File 'app/services/work_compare_service.rb', line 12

def update_work(work:, update_params:, current_user:)
  work_before = work.dup
  if work.update(update_params)
    work_compare = new(work_before, work)
    work.log_changes(work_compare, current_user.id)
    true
  else
    false
  end
end

Instance Method Details

#identical?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'app/services/work_compare_service.rb', line 31

def identical?
  @differences == {}
end