bsdcontrol.rb/lib/bsd/control.rb

53 lines
1.2 KiB
Ruby
Raw Permalink Normal View History

2024-05-12 05:59:38 +02:00
# frozen_string_literal: true
2024-05-13 00:45:10 +02:00
module BSD
end unless defined?(BSD)
2024-03-01 02:29:43 +01:00
module BSD::Control
Error = Class.new(RuntimeError)
##
# @return [BSD::Control::Context]
2024-05-13 01:01:03 +02:00
# Returns an instance of {BSD::Control::Context BSD::Control::Context}
def self.context
@context ||= BSD::Control::Context.new
end
2024-03-01 05:28:54 +01:00
##
# @return [String]
2024-05-13 01:01:03 +02:00
# Returns the version of libhbsdcontrol
2024-03-01 05:28:54 +01:00
def self.library_version
context.library_version
2024-03-01 05:28:54 +01:00
end
2024-03-01 02:29:43 +01:00
##
# @return [Array<BSD::Control::Feature>]
2024-05-13 01:01:03 +02:00
# Returns an array of available features
2024-03-01 02:29:43 +01:00
def self.available_features
context.available_features
2024-03-01 02:29:43 +01:00
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
2024-05-13 01:01:03 +02:00
# The name of a feature
2024-03-01 02:29:43 +01:00
#
# @raise [BSD::Control::Error]
2024-05-13 01:01:03 +02:00
# When a feature wasn't found
2024-03-01 02:29:43 +01:00
#
# @return [BSD::Control::Feature]
2024-05-13 01:01:03 +02: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-05-13 01:01:03 +02:00
feature || raise(Error, "'#{name}' wasn't found")
2024-03-01 02:29:43 +01:00
end
2024-05-13 00:45:10 +02:00
require_relative "control/context"
require_relative "control/feature"
require_relative "../bsdcontrol.rb.so"
2024-03-01 02:29:43 +01:00
end