Sha256: 54850ac002e4fb20e92a979494e15d60762b47c88caae2297ae97af48f105543

Contents?: true

Size: 1.6 KB

Versions: 20

Compression:

Stored size: 1.6 KB

Contents

module Skylight
  module Probes
    module ActiveModelSerializers
      module Instrumentation
        def as_json(*)
          payload = { serializer: self.class }
          ActiveSupport::Notifications.instrument("render.active_model_serializers", payload) { super }
        end
      end

      class Probe
        def install
          version = nil

          # File moved location between version
          %w[serializer serializers].each do |dir|
            require "active_model/#{dir}/version"
          rescue LoadError # rubocop:disable Lint/SuppressedException
          end

          version = Gem.loaded_specs["active_model_serializers"].version if Gem.loaded_specs["active_model_serializers"]

          if !version || version < Gem::Version.new("0.5.0")
            Skylight.error "Instrumention is only available for ActiveModelSerializers version 0.5.0 and greater."
            return
          end

          # We don't actually support the RCs correctly, requires
          # a release after 0.10.0.rc3
          if version >= Gem::Version.new("0.10.0.rc1")
            # AS::N is built in to newer versions
            return
          end

          # End users could override as_json without calling super, but it's likely safer
          # than overriding serializable_array/hash/object.

          [::ActiveModel::Serializer, ::ActiveModel::ArraySerializer].each { |klass| klass.prepend(Instrumentation) }
        end
      end
    end

    register(
      :active_model_serializers,
      "ActiveModel::Serializer",
      "active_model/serializer",
      ActiveModelSerializers::Probe.new
    )
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
skylight-6.1.0.beta lib/skylight/probes/active_model_serializers.rb
skylight-6.0.4 lib/skylight/probes/active_model_serializers.rb
skylight-6.0.3 lib/skylight/probes/active_model_serializers.rb
skylight-5.3.5 lib/skylight/probes/active_model_serializers.rb
skylight-6.0.2 lib/skylight/probes/active_model_serializers.rb
skylight-6.0.1 lib/skylight/probes/active_model_serializers.rb
skylight-6.0.0 lib/skylight/probes/active_model_serializers.rb
skylight-6.0.0.beta2 lib/skylight/probes/active_model_serializers.rb
skylight-6.0.0.beta lib/skylight/probes/active_model_serializers.rb
skylight-5.3.4 lib/skylight/probes/active_model_serializers.rb
skylight-5.3.3 lib/skylight/probes/active_model_serializers.rb
skylight-5.3.2 lib/skylight/probes/active_model_serializers.rb
skylight-5.3.1 lib/skylight/probes/active_model_serializers.rb
skylight-5.3.0 lib/skylight/probes/active_model_serializers.rb
skylight-5.2.0 lib/skylight/probes/active_model_serializers.rb
skylight-5.2.0.beta2 lib/skylight/probes/active_model_serializers.rb
skylight-5.2.0.beta lib/skylight/probes/active_model_serializers.rb
skylight-5.1.1 lib/skylight/probes/active_model_serializers.rb
skylight-5.1.0.beta3 lib/skylight/probes/active_model_serializers.rb
skylight-5.1.0.beta2 lib/skylight/probes/active_model_serializers.rb