Module: Aspen::Schemas

Defined in:
lib/aspen/schemas/grammar_schema.rb,
lib/aspen/schemas/discourse_schema.rb

Constant Summary collapse

GrammarSchema =
Dry::Schema.Params do
  config.validate_keys = true

  required(:match).array(:str?)
  required(:template).filled(:string)
end
LABEL =
/^([A-Z][A-Za-z0-9]+)+$/
LABEL_LIST =
/^([A-Z][A-Za-z0-9]+)(,\s*([A-Z][A-Za-z0-9]+))*$/
EDGE_LIST =
/^([A-Za-z\s]+)(,\s*[A-Za-z\s]+)*$/
IDENT =
/^[A-Za-z]\w*$/
IDENT_LIST =
/^(\w+)(,\s*\w+)*$/
DiscourseSchema =
Dry::Schema.Params do
  # config.validate_keys = true

  optional(:adapter)

  optional(:default).hash do
    optional(:label).filled(:string, format?: LABEL)
    optional(:attribute).filled(:string, format?: IDENT)
    optional(:attributes).filled(:hash) # TODO Validate hash
  end

  optional(:allow_only).hash do
    optional(:nodes).filled
    optional(:edges).filled
  end

  # TODO Validate that there are no reciprocal relationships
  # not listed in `only`
  # Is there a way to do something like:
  #   included_in?: [ self.only ] if self.only
  # Yes! If we make this a validation!
  optional(:reciprocal).filled(:string, format?: EDGE_LIST)

  optional(:grammar).array(GrammarSchema)
end