Sha256: 91cba972be413db3bff04be459d263367d2c3d052e3e44f7c25470ca1651f073
Contents?: true
Size: 927 Bytes
Versions: 9
Compression:
Stored size: 927 Bytes
Contents
# frozen_string_literal: true require "date" require "erb" require "pathname" require "yaml" module Mihari module Services class RuleBuilder include Dry::Monads[:result, :try] # @return [String] attr_reader :path_or_id # # Initialize # # @param [String] path_or_id # def initialize(path_or_id) @path_or_id = path_or_id end # # @return [Hash] # def data if Mihari::Rule.exists?(path_or_id) rule = Mihari::Rule.find(path_or_id) return rule.data end raise ArgumentError, "#{path_or_id} does not exist" unless Pathname(path_or_id).exist? YAML.safe_load( ERB.new(File.read(path_or_id)).result, permitted_classes: [Date, Symbol] ) end def result Try[StandardError] { RuleProxy.new(data) }.to_result end end end end
Version data entries
9 entries across 9 versions & 1 rubygems