Sha256: ffd74825818d9b163e3564ca33f628dc434aa0c56477f0e9a2afc012fcd0f4ed

Contents?: true

Size: 833 Bytes

Versions: 1

Compression:

Stored size: 833 Bytes

Contents

# frozen_string_literal: true

module Mihari
  module Services
    #
    # Rule builder
    #
    class RuleBuilder < Service
      # @return [String]
      attr_reader :path_or_id

      #
      # @param [String] path_or_id
      #
      # @return [Hash]
      #
      def data
        result = Try { Mihari::Models::Rule.find path_or_id }.to_result
        return result.value! if result.success?

        raise ArgumentError, "#{path_or_id} not found" unless Pathname(path_or_id).exist?

        YAML.safe_load(
          ERB.new(File.read(path_or_id)).result,
          permitted_classes: [Date, Symbol]
        )
      end

      #
      # @param [String] path_or_id
      #
      # @return [Mihari::Rule]
      #
      def call(path_or_id)
        @path_or_id = path_or_id

        Rule.new(**data)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mihari-7.0.0 lib/mihari/services/builders.rb