Module: Redde::WithPhoto

Extended by:
ActiveSupport::Concern
Defined in:
app/models/concerns/redde/with_photo.rb

Constant Summary collapse

QUERY =
'imageable_id = :id AND imageable_type = :type OR token in (:tokens)'.freeze

Instance Method Summary collapse

Instance Method Details

#all_photosObject



12
13
14
# File 'app/models/concerns/redde/with_photo.rb', line 12

def all_photos
  Redde::Photo.where(QUERY, id: id, type: self.class.name, tokens: tokens)
end

#assign_photosObject



16
17
18
# File 'app/models/concerns/redde/with_photo.rb', line 16

def assign_photos
  Redde::Photo.where(token: tokens).update_all(imageable_attributes)
end

#imageable_attributesObject



20
21
22
# File 'app/models/concerns/redde/with_photo.rb', line 20

def imageable_attributes
  { imageable_id: id, imageable_type: self.class.name, token: nil }
end

#tokensObject



24
25
26
# File 'app/models/concerns/redde/with_photo.rb', line 24

def tokens
  photo_tokens || []
end