Sha256: 0d55a1425e9bc2bf7207c113114b61d381e7dc1c550742db1182749e714d48ec

Contents?: true

Size: 921 Bytes

Versions: 2

Compression:

Stored size: 921 Bytes

Contents

# frozen_string_literal: true

module Mihari
  module Services
    class RuleRunner
      include Mixins::ErrorNotification

      # @return [Mihari::Services::RuleProxy]
      attr_reader :rule

      # @return [Boolean]
      attr_reader :force_overwrite

      def initialize(rule, force_overwrite:)
        @rule = rule
        @force_overwrite = force_overwrite
      end

      def force_overwrite?
        force_overwrite
      end

      #
      # @return [Boolean]
      #
      def diff?
        model = Mihari::Rule.find(rule.id)
        model.data != rule.data.deep_stringify_keys
      rescue ActiveRecord::RecordNotFound
        false
      end

      def update_or_create
        rule.model.save
      end

      #
      # @return [Mihari::Alert, nil]
      #
      def run
        analyzer = rule.analyzer

        with_error_notification do
          analyzer.run
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mihari-5.4.3 lib/mihari/services/rule_runner.rb
mihari-5.4.2 lib/mihari/services/rule_runner.rb