Use ruby version predicates to support ruby2/ruby3

This commit is contained in:
Rick Bradley 2022-08-08 16:43:36 -05:00
Родитель 43a06f1231
Коммит d57297e929
5 изменённых файлов: 26 добавлений и 5 удалений

Просмотреть файл

@ -162,7 +162,11 @@ module Entitlements
# Returns a Hash.
Contract C::None => C::HashOf[String => C::Any]
def parsed_data
@parsed_data ||= ::YAML.load(File.read(filename), permitted_classes: [Date])
@parsed_data ||= if Entitlements.ruby_version2?
::YAML.load(File.read(filename)).to_h
else
::YAML.load(File.read(filename), permitted_classes: [Date]).to_h
end
end
end
end

Просмотреть файл

@ -77,7 +77,12 @@ module Entitlements
def read(uid = nil)
@people ||= begin
Entitlements.logger.debug "Loading people from #{filename.inspect}"
raw_person_data = ::YAML.load(File.read(filename), permitted_classes: [Date]).to_h
raw_person_data = if Entitlements.ruby_version2?
::YAML.load(File.read(filename)).to_h
else
::YAML.load(File.read(filename), permitted_classes: [Date]).to_h
end
raw_person_data.map do |id, data|
[id, Entitlements::Models::Person.new(uid: id, attributes: data)]
end.to_h

Просмотреть файл

@ -58,7 +58,11 @@ module Entitlements
person_dn_format: config.fetch("person_dn_format")
}
opts[:disable_ssl_verification] = true if config.fetch("disable_ssl_verification", false)
Entitlements::Service::LDAP.new_with_cache(**opts)
if Entitlements.ruby_version2?
Entitlements::Service::LDAP.new_with_cache(opts)
else
Entitlements::Service::LDAP.new_with_cache(**opts)
end
end
end
# :nocov:

Просмотреть файл

@ -32,7 +32,11 @@ module Entitlements
raise Errno::ENOENT, "The `manager_map_file` #{manager_map_file} does not exist!"
end
YAML.load(File.read(manager_map_file), permitted_classes: [Date])
if Entitlements.ruby_version2?
::YAML.load(File.read(manager_map_file)).to_h
else
::YAML.load(File.read(manager_map_file), permitted_classes: [Date]).to_h
end
end
u = person.uid.downcase

Просмотреть файл

@ -103,7 +103,11 @@ describe Entitlements::Data::Groups::Calculated::Ruby do
it "raises an error when an unexpected data structure is created" do
filename = fixture("ldap-config/filters/filter-bad-data-structure.rb")
expect { described_class.new(filename: filename) }.to raise_error(ReturnContractError)
if Entitlements.ruby_version2?
expect { described_class.new(filename: filename) }.to raise_error(ParamContractError)
else
expect { described_class.new(filename: filename) }.to raise_error(ReturnContractError)
end
end
end