Sha256: 6949b96874c91e643b24cb5b2abe841012edfc765749296a76dd8db4385a8041

Contents?: true

Size: 832 Bytes

Versions: 25

Compression:

Stored size: 832 Bytes

Contents

begin
  require "active_support"
  require "active_support/notifications"
rescue LoadError
  warn "ActiveSupport not available"
end

module Sapience
  module Extensions
    class Notifications
      attr_reader :tags, :metric_name

      def self.use(options = {})
        new(options)
      end

      def self.subscribe(pattern, &block)
        if defined?(ActiveSupport::Notifications)
          ::ActiveSupport::Notifications.subscribe(pattern) do |*args|
            block.call ::ActiveSupport::Notifications::Event.new(*args)
          end
        else
          warn "ActiveSupport not available"
        end
      end

      def initialize(options = {})
        @tags = options[:tags] || []
      end

      def record?
        !metrics.nil?
      end

      def metrics
        Sapience.metrics
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
sapience-2.4.0 lib/sapience/extensions/notifications.rb
sapience-2.3.5 lib/sapience/extensions/notifications.rb
sapience-2.3.4 lib/sapience/extensions/notifications.rb
sapience-2.3.3 lib/sapience/extensions/notifications.rb
sapience-2.2.3 lib/sapience/extensions/notifications.rb
sapience-2.2.1 lib/sapience/extensions/notifications.rb
sapience-2.2.0 lib/sapience/extensions/notifications.rb
sapience-2.1.0 lib/sapience/extensions/notifications.rb
sapience-2.0.5 lib/sapience/extensions/notifications.rb
sapience-2.0.4 lib/sapience/extensions/notifications.rb
sapience-2.0.3 lib/sapience/extensions/notifications.rb
sapience-2.0.2 lib/sapience/extensions/notifications.rb
sapience-2.0.1 lib/sapience/extensions/notifications.rb
sapience-2.0.0 lib/sapience/extensions/notifications.rb
sapience-1.0.15 lib/sapience/extensions/notifications.rb
sapience-1.0.14 lib/sapience/extensions/notifications.rb
sapience-1.0.13 lib/sapience/extensions/notifications.rb
sapience-1.0.12 lib/sapience/extensions/notifications.rb
sapience-1.0.11 lib/sapience/extensions/notifications.rb
sapience-1.0.10 lib/sapience/extensions/notifications.rb