Sha256: 5c9039c22a0c3b8147d4bf86a1daa422a6e19b302e5af39cf0be330a752fff9a

Contents?: true

Size: 1.05 KB

Versions: 7

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

module Mihari
  module Services
    class RuleRunner
      include Dry::Monads[:result, :try]

      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
        rule.analyzer.run
      end

      #
      # @return [Dry::Monads::Result::Success<Mihari::Alert, nil>, Dry::Monads::Result::Failure]
      #
      def result
        Try[StandardError] { run }.to_result
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
mihari-5.5.0 lib/mihari/services/rule_runner.rb
mihari-5.4.9 lib/mihari/services/rule_runner.rb
mihari-5.4.8 lib/mihari/services/rule_runner.rb
mihari-5.4.7 lib/mihari/services/rule_runner.rb
mihari-5.4.6 lib/mihari/services/rule_runner.rb
mihari-5.4.5 lib/mihari/services/rule_runner.rb
mihari-5.4.4 lib/mihari/services/rule_runner.rb