Use ruby version predicates to support ruby2/ruby3
This commit is contained in:
Родитель
43a06f1231
Коммит
d57297e929
|
@ -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
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче