Control#feature! -> Control#feature

This commit is contained in:
0x1eef 2024-03-08 01:23:16 -03:00
parent d9042ce213
commit e0fab16bce
6 changed files with 14 additions and 14 deletions

View file

@ -33,7 +33,7 @@ The example enables the mprotect feature for the emacs binary:
# As a root account # As a root account
require 'hbsdctl' require 'hbsdctl'
BSD::Control BSD::Control
.feature!(:mprotect) .feature(:mprotect)
.enable!("/usr/local/bin/emacs-29.2") .enable!("/usr/local/bin/emacs-29.2")
``` ```

View file

@ -18,7 +18,7 @@ module BSD::Control
## ##
# @example # @example
# BSD::Control # BSD::Control
# .feature!(:mprotect) # .feature(:mprotect)
# .enable!("/usr/local/bin/firefox") # .enable!("/usr/local/bin/firefox")
# #
# @param [String] name # @param [String] name
@ -29,7 +29,7 @@ module BSD::Control
# #
# @return [BSD::Control::Feature] # @return [BSD::Control::Feature]
# Returns an instance of BSD::Control::Feature. # Returns an instance of BSD::Control::Feature.
def self.feature!(name) def self.feature(name)
feature = Feature.available.find { _1.name == name.to_s } feature = Feature.available.find { _1.name == name.to_s }
feature ? feature : raise(Error, "feature '#{name}' wasn't found") feature ? feature : raise(Error, "feature '#{name}' wasn't found")
end end

View file

@ -6,7 +6,7 @@ module BSD::Control
def test_enable_mprotect def test_enable_mprotect
touch(file) touch(file)
assert BSD::Control.feature!(:mprotect).enable!(file), assert BSD::Control.feature(:mprotect).enable!(file),
"The enable! method should have returned true" "The enable! method should have returned true"
ensure ensure
rm(file) rm(file)
@ -15,7 +15,7 @@ module BSD::Control
def test_enable_mprotect_zero_permissions def test_enable_mprotect_zero_permissions
touch(file) touch(file)
chmod(0, file) chmod(0, file)
assert BSD::Control.feature!(:mprotect).enable!(file), assert BSD::Control.feature(:mprotect).enable!(file),
"The enable! method should have returned true" "The enable! method should have returned true"
ensure ensure
rm(file) rm(file)
@ -23,7 +23,7 @@ module BSD::Control
def test_enable_mprotect_nonexistent_file def test_enable_mprotect_nonexistent_file
assert_raises(BSD::Control::Error) do assert_raises(BSD::Control::Error) do
BSD::Control.feature!(:mprotect).enable!(file) BSD::Control.feature(:mprotect).enable!(file)
end end
end end

View file

@ -7,16 +7,16 @@ module BSD::Control
def test_mprotect_sysdef_status def test_mprotect_sysdef_status
touch(file) touch(file)
assert_equal :sysdef, assert_equal :sysdef,
BSD::Control.feature!(:mprotect).status(file) BSD::Control.feature(:mprotect).status(file)
ensure ensure
rm(file) rm(file)
end end
def test_mprotect_enabled_status def test_mprotect_enabled_status
touch(file) touch(file)
BSD::Control.feature!(:mprotect).enable!(file) BSD::Control.feature(:mprotect).enable!(file)
assert_equal :enabled, assert_equal :enabled,
BSD::Control.feature!(:mprotect).status(file) BSD::Control.feature(:mprotect).status(file)
ensure ensure
rm(file) rm(file)
end end
@ -24,9 +24,9 @@ module BSD::Control
def test_mprotect_disabled_status def test_mprotect_disabled_status
touch(file) touch(file)
BSD::Control.feature!(:mprotect).disable!(file) BSD::Control.feature(:mprotect).disable!(file)
assert_equal :disabled, assert_equal :disabled,
BSD::Control.feature!(:mprotect).status(file) BSD::Control.feature(:mprotect).status(file)
ensure ensure
rm(file) rm(file)
end end

View file

@ -10,7 +10,7 @@ module BSD::Control
BSD::Control::Error, BSD::Control::Error,
"This operation requires root privileges." "This operation requires root privileges."
) do ) do
BSD::Control.feature!(:mprotect).enable!(file) BSD::Control.feature(:mprotect).enable!(file)
end end
ensure ensure
rm(file) rm(file)

View file

@ -3,12 +3,12 @@ module BSD::Control
class FeatureBangTest < Test::Unit::TestCase class FeatureBangTest < Test::Unit::TestCase
def test_mprotect_feature def test_mprotect_feature
assert_instance_of BSD::Control::Feature, assert_instance_of BSD::Control::Feature,
BSD::Control.feature!(:mprotect) BSD::Control.feature(:mprotect)
end end
def test_nonexistent_feature def test_nonexistent_feature
assert_raises(BSD::Control::Error) do assert_raises(BSD::Control::Error) do
BSD::Control.feature!(:non_existent_feature) BSD::Control.feature(:non_existent_feature)
end end
end end
end end