Sha256: cdc710ab5a33036d0d8d229e1a844f3d0158102d175ea090a2d2f33aaa922550

Contents?: true

Size: 512 Bytes

Versions: 4

Compression:

Stored size: 512 Bytes

Contents

# frozen_string_literal: true

module Bridgetown
  module ComponentValidation
    def self.included(klass)
      klass.attr_reader :frontmatter
    end

    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
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
bridgetown-view-component-2.0.0 lib/bridgetown-view-component/bridgetown/component_validation.rb
bridgetown-view-component-1.0.0 lib/bridgetown-view-component/bridgetown/component_validation.rb
bridgetown-view-component-0.7.0 lib/bridgetown-view-component/bridgetown/component_validation.rb
bridgetown-view-component-0.6.0 lib/bridgetown-view-component/bridgetown/component_validation.rb