require 'yaml' module JSONiCal module VEVENTSchema class BadVersionError < ArgumentError; end supported_versions = (1..2) versions = supported_versions.map do |version| [:"v#{version}", YAML.load_file("schemas/v#{version}.yml").freeze] end SCHEMAS = Hash[versions] private_constant(:SCHEMAS) def self.validate!(payload, version:) schema = SCHEMAS[version.to_sym] raise(BadVersionError) if schema.nil? JSON::Validator.validate!(schema, payload) end end end