foundationdb/bindings/ruby/lib/fdb.rb

82 lines
2.4 KiB
Ruby
Raw Normal View History

2017-05-26 04:48:44 +08:00
#
# fdb.rb
#
# This source file is part of the FoundationDB open source project
#
# Copyright 2013-2018 Apple Inc. and the FoundationDB project authors
#
2017-05-26 04:48:44 +08:00
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
2017-05-26 04:48:44 +08:00
# http://www.apache.org/licenses/LICENSE-2.0
#
2017-05-26 04:48:44 +08:00
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# FoundationDB Ruby API
# Documentation for this API can be found at
2018-04-20 02:12:27 +08:00
# https://apple.github.io/foundationdb/api-ruby.html
2017-05-26 04:48:44 +08:00
module FDB
@@chosen_version = -1
def self.is_api_version_selected?()
@@chosen_version >= 0
end
def self.get_api_version()
if self.is_api_version_selected?()
return @@chosen_version
else
raise "FDB API version not selected"
end
end
2017-05-26 04:48:44 +08:00
def self.api_version(version)
2018-07-06 09:08:19 +08:00
header_version = 600
if self.is_api_version_selected?()
if @@chosen_version != version
2017-05-26 04:48:44 +08:00
raise "FDB API already loaded at version #{@@chosen_version}."
end
return
end
if version < 14
raise "FDB API versions before 14 are not supported"
end
if version > header_version
raise "Latest known FDB API version is #{header_version}"
end
@@chosen_version = version
require_relative 'fdbimpl'
err = FDBC.fdb_select_api_version_impl(version, header_version)
if err.nonzero?
if err == 2203
max_supported_version = FDBC.fdb_get_max_api_version()
if header_version > max_supported_version
raise "This version of the FoundationDB Ruby binding is not supported by the installed FoundationDB C library. The binding requires a library that supports API version #{header_version}, but the installed library supports a maximum version of #{max_supported_version}."
else
raise "API version #{version} is not supported by the installed FoundationDB C library."
end
end
raise "FoundationDB API version error"
end
require_relative 'fdbtuple'
require_relative 'fdbdirectory'
if version > 22
require_relative 'fdblocality'
end
return
end
end