Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ruby 2.5 compatibility #12

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion lib/front_matter_parser/loader/yaml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,20 @@ def initialize(allowlist_classes: [])
# @param string [String] front matter string representation
# @return [Hash] front matter hash representation
def call(string)
YAML.safe_load(string, permitted_classes: allowlist_classes)
if safe_load_with_permitted_classes_arg?
YAML.safe_load(string, permitted_classes: allowlist_classes)
else
YAML.safe_load(string, allowlist_classes)
end
end

def safe_load_with_permitted_classes_arg?
# This `permitted_classes` keyword argument was
# introduced in Ruby 2.6, and therefore is not
# compatible with Ruby 2.5 and earlier.
YAML
.public_method(:safe_load).parameters
.any? { |type, name| type == :key && name == :permitted_classes }
end
end
end
Expand Down