Class: Textus::Doctor::Check::SchemaViolations

Inherits:
Textus::Doctor::Check show all
Defined in:
lib/textus/doctor/check/schema_violations.rb

Instance Method Summary collapse

Methods inherited from Textus::Doctor::Check

#initialize, name_key

Constructor Details

This class inherits a constructor from Textus::Doctor::Check

Instance Method Details

#callObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/textus/doctor/check/schema_violations.rb', line 5

def call
  result = Textus::Doctor::Validator.new(
    reader: ->(key, ctnr, c) { Textus::Action::Get.new(key: key).call(container: ctnr, call: c) },
    manifest: @container.manifest,
    audit_log: @container.audit_log,
    schema_for: ->(name) { @container.schemas.fetch_or_nil(name) },
  ).call(container: @container, call: Textus::Call.build(role: Textus::Role::DEFAULT))

  result["violations"].map do |v|
    fix = v["expected"] &&
          "field '#{v["field"]}' should be written by '#{v["expected"]}' (last writer: #{v["last_writer"]})"
    {
      "code" => v["code"],
      "level" => "error",
      "subject" => v["key"],
      "message" => v["message"] || "#{v["code"]} on #{v["key"]}",
      "fix" => fix,
    }.compact
  end
end