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

Add Ruby 3.3 support #136

Merged
merged 1 commit into from
Dec 26, 2023
Merged
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
21 changes: 2 additions & 19 deletions lib/rggen/core/input_base/yaml_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,8 @@ def mapping_key?
end

class Visitor < ::Psych::Visitors::ToRuby
if ::Psych::VERSION >= '3.2.0'
def initialize(scalar_scanner, class_loader)
super(scalar_scanner, class_loader, symbolize_names: true)
end
def initialize(scalar_scanner, class_loader)
super(scalar_scanner, class_loader, symbolize_names: true)
end

def accept(node)
Expand All @@ -79,7 +77,6 @@ def override_object?(node)
def load_yaml(file)
parse_yaml(File.binread(file), file)
.then { |result| to_ruby(result) }
.then { |result| symbolize_names(result) }
end

def parse_yaml(yaml, file)
Expand All @@ -93,20 +90,6 @@ def to_ruby(result)
ss = ::Psych::ScalarScanner.new(cl)
Visitor.new(ss, cl).accept(result)
end

def symbolize_names(result)
return result if ::Psych::VERSION >= '3.2.0'

if result.match_class?(Hash)
result
.transform_keys!(&:to_sym)
.transform_values!(&method(:symbolize_names))
elsif result.match_class?(Array)
result.map! { |value| symbolize_names(value) }
end

result
end
end
end
end
Expand Down