Sha256: faa17c9f5aa45ec5c25eb6ba29b1353898f2bf8721b444b74e121a613ba2a709

Contents?: true

Size: 751 Bytes

Versions: 9

Compression:

Stored size: 751 Bytes

Contents

# frozen_string_literal: true

require "date"

require "erb"
require "pathname"
require "yaml"

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

      # @return [String]
      attr_reader :path

      #
      # Initialize
      #
      # @param [String] path
      #
      def initialize(path)
        @path = path
      end

      #
      # @return [Hash]
      #
      def data
        raise ArgumentError, "#{path} does not exist" unless Pathname(path).exist?

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

      def result
        Try[StandardError] { AlertProxy.new(data) }.to_result
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

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