Sha256: 57c11c06a1f7a68fbdb1bb8dfbaaddd44efed4476249b62360a2318ec310eb46

Contents?: true

Size: 1.07 KB

Versions: 14

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

module Mihari
  module Emitters
    #
    # Base class for emitters
    #
    class Base < Actor
      # @return [Mihari::Rule]
      attr_reader :rule

      #
      # @param [Mihari::Rule] rule
      # @param [Hash, nil] options
      #
      def initialize(rule:, options: nil)
        super(options: options)

        @rule = rule
      end

      #
      # @param [Array<Mihari::Models::Artifact>] artifacts
      #
      def call(artifacts)
        raise NotImplementedError, "You must implement #{self.class}##{__method__}"
      end

      #
      # @return [Dry::Monads::Result::Success<Object>, Dry::Monads::Result::Failure]
      #
      def result(artifacts)
        Try[StandardError] do
          retry_on_error(
            times: retry_times,
            interval: retry_interval,
            exponential_backoff: retry_exponential_backoff
          ) { call(artifacts) }
        end.to_result
      end

      class << self
        def inherited(child)
          super
          Mihari.emitters << child
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
mihari-7.1.0 lib/mihari/emitters/base.rb
mihari-7.0.5 lib/mihari/emitters/base.rb
mihari-7.0.4 lib/mihari/emitters/base.rb
mihari-7.0.3 lib/mihari/emitters/base.rb
mihari-7.0.2 lib/mihari/emitters/base.rb
mihari-7.0.1 lib/mihari/emitters/base.rb
mihari-7.0.0 lib/mihari/emitters/base.rb
mihari-6.3.0 lib/mihari/emitters/base.rb
mihari-6.2.0 lib/mihari/emitters/base.rb
mihari-6.1.0 lib/mihari/emitters/base.rb
mihari-6.0.0 lib/mihari/emitters/base.rb
mihari-5.7.2 lib/mihari/emitters/base.rb
mihari-5.7.1 lib/mihari/emitters/base.rb
mihari-5.7.0 lib/mihari/emitters/base.rb