Class: Mihari::Web::Endpoints::Rules::RuleCreateUpdater

Inherits:
Service
  • Object
show all
Defined in:
lib/mihari/web/endpoints/rules.rb

Instance Method Summary collapse

Methods inherited from Service

call, #result, result

Instance Method Details

#call(yaml, overwrite: true) ⇒ Mihari::Models::Rule

Returns:

Raises:



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/mihari/web/endpoints/rules.rb', line 17

def call(yaml, overwrite: true)
  rule = Rule.from_yaml(yaml)

  # To invoke ActiveRecord::RecordNotFound
  Models::Rule.find(rule.id) if overwrite

  raise IntegrityError, "ID:#{rule.id} already registered" if rule.exists? && !overwrite

  rule.update_or_create
  rule
end