Class: Api::V5::RestaurantTagSerializer

Inherits:
BaseSerializer show all
Defined in:
app/serializers/api/v5/restaurant_tag_serializer.rb

Overview

restaurant tags serializer

Instance Method Summary collapse

Methods inherited from BaseSerializer

#full_attachment_url, #safe_translation_attr

Methods inherited from ApplicationSerializer

decorate_attributes, decorator

Instance Method Details

#ads?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'app/serializers/api/v5/restaurant_tag_serializer.rb', line 49

def ads?
  instance_options[:advertise].present?
end

#object_cache_keyObject

Overrides the default cache key generation method. Ref. github.com/rails-api/active_model_serializers/blob/0-10-stable/lib/active_model/serializer/concerns/caching.rb

Need to overrides the default cache key generation method, because the current cache key generation in the application_serializer is returns the same object, even though the object has been updated.



59
60
61
62
63
64
# File 'app/serializers/api/v5/restaurant_tag_serializer.rb', line 59

def object_cache_key
  object_time_safe = object.updated_at
  object_time_safe = object_time_safe.strftime('%Y%m%d%H%M%S%9N') if object_time_safe.respond_to?(:strftime)

  "#{self.class.name}:#{object.id}:#{I18n.locale}:#{object_time_safe}:#{CityHash.hash32(instance_options)}:#{object.restaurant_tags_totals.cache_key}"
end

#positionObject



44
45
46
47
# File 'app/serializers/api/v5/restaurant_tag_serializer.rb', line 44

def position
  advertise = instance_options[:advertise].find_by(advertisable_id: object.id)
  advertise.position
end