Class: ApplicationSerializer

Inherits:
ActiveModel::Serializer
  • Object
show all
Includes:
AmsLazyRelationships::Core, ElasticAPM::SpanHelpers
Defined in:
app/serializers/application_serializer.rb

Overview

typed: ignore

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.decorate_attributes(klass, *args) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/serializers/application_serializer.rb', line 9

def self.decorate_attributes(klass, *args)
  define_method :decorated_object do
    ElasticAPM.with_span('decorated_object') do |_span|
      @decorated_object ||= klass.new object
    end
  end

  args.each do |method|
    attribute method do
      ElasticAPM.with_span("attribute.#{method}") do |_span|
        decorated_object.send method
      end
    end
  end
end

.decorator(decorator_class) ⇒ Object



25
26
27
28
29
# File 'app/serializers/application_serializer.rb', line 25

def self.decorator(decorator_class)
  define_method :decorator do
    "#{decorator_class.to_s.camelize}Decorator".constantize
  end
end

Instance Method Details

#object_cache_keyObject



31
32
33
34
35
36
37
38
# File 'app/serializers/application_serializer.rb', line 31

def object_cache_key
  @object_cache_key ||= ElasticAPM.with_span('object_cache_key') do
    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)}"
  end
end