Sha256: e5f9200d2724ac86d008e68d677f78dadf1bc0a38b77d32e91ae056f6e6974f6

Contents?: true

Size: 1.16 KB

Versions: 1

Compression:

Stored size: 1.16 KB

Contents

require "influxdb/rails/logger"

module InfluxDB
  module Rails
    module Middleware
      # Subscriber acts as base class for different *Subscriber classes,
      # which are intended as ActiveSupport::Notifications.subscribe
      # consumers.
      class Subscriber
        include InfluxDB::Rails::Logger

        attr_reader :configuration

        def initialize(configuration)
          @configuration = configuration
        end

        def call(*)
          raise NotImplementedError, "must be implemented in subclass"
        end

        private

        def tags(tags)
          result = tags.merge(InfluxDB::Rails.current.tags)
          result = configuration.tags_middleware.call(result)
          result.reject! do |_, value|
            value.nil? || value == ""
          end
          result
        end

        def enabled?
          configuration.instrumentation_enabled? &&
            !configuration.ignore_current_environment?
        end

        def location
          current = InfluxDB::Rails.current
          [
            current.controller,
            current.action,
          ].reject(&:blank?).join("#")
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
experimental-influxdb-rails-1.0.0.beta5 lib/influxdb/rails/middleware/subscriber.rb