Sha256: 3f291ab77479798e98d1d1c6153414b5bc72065e0b4b289f14d09e15e2ec4d36

Contents?: true

Size: 845 Bytes

Versions: 2

Compression:

Stored size: 845 Bytes

Contents

# frozen_string_literal: true

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

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

      def initialize(rule)
        @rule = rule
      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

2 entries across 2 versions & 1 rubygems

Version Path
mihari-5.6.1 lib/mihari/services/rule_runner.rb
mihari-5.6.0 lib/mihari/services/rule_runner.rb