Class: Api::V5::RestaurantTagSerializer
- Inherits:
-
BaseSerializer
- Object
- ActiveModel::Serializer
- ApplicationSerializer
- BaseSerializer
- Api::V5::RestaurantTagSerializer
- Defined in:
- app/serializers/api/v5/restaurant_tag_serializer.rb
Overview
restaurant tags serializer
Instance Method Summary collapse
- #ads? ⇒ Boolean
-
#object_cache_key ⇒ Object
Overrides the default cache key generation method.
- #position ⇒ Object
Methods inherited from BaseSerializer
#full_attachment_url, #safe_translation_attr
Methods inherited from ApplicationSerializer
decorate_attributes, decorator
Instance Method Details
#ads? ⇒ Boolean
49 50 51 |
# File 'app/serializers/api/v5/restaurant_tag_serializer.rb', line 49 def ads? [:advertise].present? end |
#object_cache_key ⇒ Object
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()}:#{object..cache_key}" end |
#position ⇒ Object
44 45 46 47 |
# File 'app/serializers/api/v5/restaurant_tag_serializer.rb', line 44 def position advertise = [:advertise].find_by(advertisable_id: object.id) advertise.position end |