Class: Mihari::Services::RuleBuilder

Inherits:
Mihari::Service show all
Defined in:
lib/mihari/services/builders.rb

Overview

Rule builder

Instance Method Summary collapse

Methods inherited from Mihari::Service

call, #result, result

Instance Method Details

#call(path_or_id) ⇒ Mihari::Rule

Parameters:

  • path_or_id (String)

Returns:

Raises:

  • (ArgumentError)


14
15
16
17
18
19
20
21
# File 'lib/mihari/services/builders.rb', line 14

def call(path_or_id)
  res = Try { Rule.from_model Mihari::Models::Rule.find(path_or_id) }
  return res.value! if res.value?

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

  Rule.from_yaml ERB.new(File.read(path_or_id)).result
end