Current section
Files
Jump to
Current section
Files
lib/verifiers/verify_label_pascal_case.ex
# SPDX-FileCopyrightText: 2025 ash_neo4j contributors <https://github.com/diffo-dev/ash_neo4j/graphs.contributors>
#
# SPDX-License-Identifier: MIT
defmodule AshNeo4j.Verifiers.VerifyLabelPascalCase do
@moduledoc "Verifies that the label is PascalCase"
use Spark.Dsl.Verifier
alias Spark.Dsl.Verifier
alias Spark.Error.DslError
@regex ~r/^[A-Z][a-zA-Z0-9]*$/
@impl true
def verify(dsl) do
resource = Verifier.get_persisted(dsl, :module)
module = String.to_atom(List.last(Module.split(resource)))
label = Verifier.get_option(dsl, [:neo4j], :label, module)
cond do
label == nil ->
{:error,
DslError.exception(
module: resource,
message: "label: missing"
)}
Regex.match?(@regex, Atom.to_string(label)) ->
:ok
true ->
{:error,
DslError.exception(
module: resource,
message: "label: neo4j label must be PascalCase"
)}
end
end
end