Class: Uniword::Validation::Rules::ModelRule

Inherits:
Base
  • Object
show all
Defined in:
lib/uniword/validation/rules/model_rule.rb

Overview

Base class for in-memory (model-level) validation rules.

Model rules run against a Rules::ModelContext — the pre-save front-end of the validation engine — and inspect the document model directly instead of parsing package XML.

Examples:

Implement a model rule

class MyModelRule < ModelRule
  def code = "DOC-900"

  def check(context)
    return [] if context.document.body

    [issue("Document body is missing")]
  end
end

Rules::Registry.register(MyModelRule)

Instance Method Summary collapse

Methods inherited from Base

#applicable?, #category, #check, #code, #description, #severity, #validity_rule

Instance Method Details

#context_typeSymbol

Model rules consume the in-memory ModelContext.

Returns:

  • (Symbol)

    :model



28
29
30
# File 'lib/uniword/validation/rules/model_rule.rb', line 28

def context_type
  :model
end