bsdcontrol.rb/lib/bsd/control.rb

41 lines
915 B
Ruby
Raw Normal View History

2024-03-01 02:29:43 +01:00
module BSD::Control
require_relative "control/feature"
Error = Class.new(RuntimeError)
2024-03-01 05:28:54 +01:00
##
# @return [String]
# Returns the version of libhbsdcontrol.
def self.library_version
FFI.library_version
end
2024-03-01 02:29:43 +01:00
##
# @return [Array<BSD::Control::Feature>]
2024-03-08 06:17:15 +01:00
# Returns an array of available features.
2024-03-01 02:29:43 +01:00
def self.available_features
Feature.available
end
##
# @example
# BSD::Control
2024-03-08 05:23:16 +01:00
# .feature(:mprotect)
2024-03-08 06:17:15 +01:00
# .enable!("/usr/local/bin/emacs-29.2")
2024-03-01 02:29:43 +01:00
#
# @param [String] name
# The name of a feature.
#
# @raise [BSD::Control::Error]
# When a feature is not found.
#
# @return [BSD::Control::Feature]
2024-03-08 06:17:15 +01:00
# Returns an instance of {BSD::Control::Feature BSD::Control::Feature}.
2024-03-08 05:23:16 +01:00
def self.feature(name)
2024-03-08 06:17:15 +01:00
feature = available_features.find { _1.name == name.to_s }
2024-03-01 02:29:43 +01:00
feature ? feature : raise(Error, "feature '#{name}' wasn't found")
end
module FFI
end
end