Class: Canvas::Validator::LayoutSchema

Inherits:
Object
  • Object
show all
Defined in:
lib/canvas/validators/layout_schema.rb

Overview

:documented: This class is used to validate a layout definition, part of block schema. Example of a valid layout definition: { "attributes" => { "title" => { "type" => "string" } ... }, "layout" => [ { "label" => "Design", "type" => "tab", "elements" => [ "heading", { "type" => "accordion", "label" => "Logo", "elements" => [ "description", { "type" => "attribute", "name" => "logo_alt" }, "title" ] }, { "type" => "accordion_toggle", "toggle_attribute" => "cta_enabled", "elements" => [ "cta_text", "cta_target" ] } ] } ] }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schema:) ⇒ LayoutSchema

Returns a new instance of LayoutSchema.



48
49
50
51
# File 'lib/canvas/validators/layout_schema.rb', line 48

def initialize(schema:)
  @schema = schema
  @errors = []
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



46
47
48
# File 'lib/canvas/validators/layout_schema.rb', line 46

def errors
  @errors
end

Instance Method Details

#validateObject



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/canvas/validators/layout_schema.rb', line 53

def validate
  @errors = []

  if ensure_valid_format
    ensure_no_unrecognized_keys
    ensure_no_duplicate_keys
    ensure_accordion_toggles_are_valid
    ensure_unique_tabs
  end

  @errors.empty?
end