module Bridgetown::ComponentValidation

Public Class Methods

included(klass) click to toggle source
# File lib/bridgetown-view-component/bridgetown/component_validation.rb, line 5
def self.included(klass)
  klass.attr_reader :frontmatter
end

Public Instance Methods

frontmatter=(yaml_data) click to toggle source
# File lib/bridgetown-view-component/bridgetown/component_validation.rb, line 9
def frontmatter=(yaml_data)
  @frontmatter = yaml_data.with_dot_access

  frontmatter.validate&.each do |variable, type|
    unless send(variable).is_a?(Kernel.const_get(type))
      raise "Validation error while rendering #{self.class}: " \
            "`#{variable}' is not of type `#{type}'"
    end
  end
end