Class: Trackers::CommonService

Inherits:
Object
  • Object
show all
Includes:
ImageHelper
Defined in:
app/services/partner_service/trackers/common_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ImageHelper

#fix_image_url

Constructor Details

#initialize(record:, params:, nav:) ⇒ CommonService

Initializes the service with the given record, parameters, and navigation context.

Parameters:

  • record (Object)

    The record being tracked for changes.

  • params (Hash)

    The new parameters to compare with the record's current attributes.

  • nav (String)

    The navigation context for categorizing changes.



22
23
24
25
26
27
# File 'app/services/partner_service/trackers/common_service.rb', line 22

def initialize(record:, params:, nav:)
  @record = record
  @params = params
  @navigation = nav
  @changes = {}
end

Instance Attribute Details

#changesObject

Returns the value of attribute changes.



15
16
17
# File 'app/services/partner_service/trackers/common_service.rb', line 15

def changes
  @changes
end

Returns the value of attribute footer_text.



15
16
17
# File 'app/services/partner_service/trackers/common_service.rb', line 15

def footer_text
  @footer_text
end

Returns the value of attribute navigation.



15
16
17
# File 'app/services/partner_service/trackers/common_service.rb', line 15

def navigation
  @navigation
end

Instance Method Details

#callvoid

This method returns an undefined value.

Tracks changes to the record, comparing the old and new values in the parameters. Updates the `changes` hash with the differences for both text and image fields.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/services/partner_service/trackers/common_service.rb', line 33

def call
  record_type = @record.class.name.to_s

  old_data = @record.slice(*@params.keys.map(&:to_s))
  new_data = @params

  new_data.each do |key, new_value|
    next if skiped_keys.include?(key.to_s)

    old_value = old_data[key.to_s]

    if key.to_s.include?('logo') || key.to_s.include?('item')
      key = :cover_image if key == :item
      handle_single_image_change(key, old_value, new_value, record_type)
    else
      key, old_value, new_value = transform_text_changes(key, old_value, new_value)
      format_text_change(key, old_value, new_value, record_type)
    end
  end
end