Class: Trackers::GalleryService

Inherits:
Object
  • Object
show all
Defined in:
app/services/partner_service/trackers/gallery_service.rb

Overview

The GalleryService class tracks changes to the restaurant's image gallery. It monitors additions and deletions of pictures, storing changes in a format suitable for notifying managers or logging actions.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGalleryService

Returns a new instance of GalleryService.



8
9
10
# File 'app/services/partner_service/trackers/gallery_service.rb', line 8

def initialize
  @archived_images_ids = []
end

Instance Attribute Details

#archived_images_idsObject

Returns the value of attribute archived_images_ids.



6
7
8
# File 'app/services/partner_service/trackers/gallery_service.rb', line 6

def archived_images_ids
  @archived_images_ids
end

#changesObject

Returns the value of attribute changes.



6
7
8
# File 'app/services/partner_service/trackers/gallery_service.rb', line 6

def changes
  @changes
end

Returns the value of attribute footer_text.



6
7
8
# File 'app/services/partner_service/trackers/gallery_service.rb', line 6

def footer_text
  @footer_text
end

Returns the value of attribute navigation.



6
7
8
# File 'app/services/partner_service/trackers/gallery_service.rb', line 6

def navigation
  @navigation
end

Instance Method Details

#track_added_picture(picture) ⇒ void

This method returns an undefined value.

Tracks the addition of a picture to the gallery.

Parameters:

  • picture (Picture)

    The picture being added. The picture should respond to `item.url`.



45
46
47
48
49
50
51
52
53
54
# File 'app/services/partner_service/trackers/gallery_service.rb', line 45

def track_added_picture(picture)
  @changes = {
    gallery: {
      added: [MyImageHelper.new.fix_image_url(picture.item.url)],
      label: '1 Image has been added to the gallery',
      type: 'image',
    },
  }
  @navigation = 'photo'
end

#track_deleted_picture(pictures) ⇒ void

This method returns an undefined value.

Tracks the deletion of pictures from the gallery.

Parameters:

  • pictures (Array<Picture>)

    The array of pictures being deleted. Each picture should respond to `valid?` and `id`.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/services/partner_service/trackers/gallery_service.rb', line 17

def track_deleted_picture(pictures)
  return if pictures.blank?

  if pictures.all?(&:valid?)
    archived_images(pictures, :item)

    removed = []
    @archived_images_ids.each do |id|
      img_url = ArchivedImage.find(id).image.url
      removed << MyImageHelper.new.fix_image_url(img_url)
    end

    @changes = {
      gallery: {
        removed: removed,
        label: "#{pictures.count} Image has been deleted from the gallery",
        type: 'image',
      },
    }
  end
  @navigation = 'photo'
end