From a59f80ddcace7f073cc485f933123642a305ffbc Mon Sep 17 00:00:00 2001 From: Hugo Peixoto Date: Mon, 1 Jan 2024 16:29:12 +0000 Subject: [PATCH] Workaround for ruby <3 --- checkdates.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/checkdates.rb b/checkdates.rb index 13013a1..d335f68 100755 --- a/checkdates.rb +++ b/checkdates.rb @@ -3,13 +3,22 @@ require 'yaml' require 'date' +def yaml_load(text) + # not sure if 3.0.0 is the right threshold, but it works + if (RUBY_VERSION.split(".").map(&:to_i) <=> [3,0,0]) < 0 + YAML.load(text) + else + YAML.load(text, permitted_classes: [Symbol, Date, Time]) + end +end + class YAMLFrontMatter PATTERN = /\A(---\r?\n(.*?)\n?^---\s*$\n?)/m.freeze class << self def extract(content) if content =~ PATTERN - [YAML.load(Regexp.last_match(2), permitted_classes: [Symbol, Date, Time]), content.sub(Regexp.last_match(1), "")] + [yaml_load(Regexp.last_match(2)), content.sub(Regexp.last_match(1), "")] else [{}, content] end