Class: Trackers::ThumbnailService
- Inherits:
-
Object
- Object
- Trackers::ThumbnailService
- Includes:
- Helper
- Defined in:
- app/services/partner_service/trackers/thumbnail_service.rb
Overview
This service tracks changes to restaurant thumbnail images, including added, removed, and updated thumbnails. It uses the `Trackers::Helper` module to log these changes.
Instance Attribute Summary collapse
-
#changes ⇒ Object
Returns the value of attribute changes.
-
#footer_text ⇒ Object
Returns the value of attribute footer_text.
-
#navigation ⇒ Object
Returns the value of attribute navigation.
Instance Method Summary collapse
-
#initialize ⇒ ThumbnailService
constructor
Initializes a new instance of the ThumbnailService class.
-
#track_thumbnails(old_ids, new_ids) ⇒ void
Tracks changes to restaurant thumbnails, including additions, removals, and updates.
Constructor Details
#initialize ⇒ ThumbnailService
Initializes a new instance of the ThumbnailService class.
10 11 12 |
# File 'app/services/partner_service/trackers/thumbnail_service.rb', line 10 def initialize @changes = {} end |
Instance Attribute Details
#changes ⇒ Object
Returns the value of attribute changes.
7 8 9 |
# File 'app/services/partner_service/trackers/thumbnail_service.rb', line 7 def changes @changes end |
#footer_text ⇒ Object
Returns the value of attribute footer_text.
7 8 9 |
# File 'app/services/partner_service/trackers/thumbnail_service.rb', line 7 def @footer_text end |
#navigation ⇒ Object
Returns the value of attribute navigation.
7 8 9 |
# File 'app/services/partner_service/trackers/thumbnail_service.rb', line 7 def @navigation end |
Instance Method Details
#track_thumbnails(old_ids, new_ids) ⇒ void
This method returns an undefined value.
Tracks changes to restaurant thumbnails, including additions, removals, and updates.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/services/partner_service/trackers/thumbnail_service.rb', line 19 def track_thumbnails(old_ids, new_ids) return if (old_ids - new_ids).blank? && (new_ids - old_ids).blank? removed_ids = old_ids - new_ids added_ids = new_ids - old_ids old_thumbnails = Restaurants::Picture.where(id: removed_ids) new_thumbnails = Restaurants::Picture.where(id: added_ids) # Calculate the maximum length of new_thumbnails and old_thumbnails max_length = [new_thumbnails.size, old_thumbnails.size].max # Iterate over the index up to max_length to handle differing lengths (0...max_length).each do |i| new_thumbnail = new_thumbnails[i] old_thumbnail = old_thumbnails[i] next if new_thumbnail&.id == old_thumbnail&.id if new_thumbnail && old_thumbnail # Log changes when a thumbnail is updated. if old_thumbnail.id != new_thumbnail.id label = 'Thumbnail has been changed' track_changes(label: label, nav: 'restaurant', type: 'image', old_value: old_thumbnail.item.url, new_value: new_thumbnail.item.url) end elsif new_thumbnail.present? && old_thumbnail.blank? # Log additions when a new thumbnail is added. label = 'Thumbnail has been added' track_changes(label: label, nav: 'restaurant', type: 'image', old_value: nil, new_value: new_thumbnail.item.url) elsif old_thumbnail.present? && new_thumbnail.blank? # Log removals when a thumbnail is removed. label = 'Thumbnail has been removed' track_changes(label: label, nav: 'restaurant', type: 'image', old_value: old_thumbnail.item.url, new_value: nil) end end end |