Mode::Permission
The Kanrisuru::Mode::Permission
class helps manages an invidual permission for a mode ownership type. This is defined in the Mode class as an owner
, group
, or other.
Public Class Methods
new
Create a new instance of the permission class. Need to pass in both the numeric and symbolic representation of the permission to manage.
permission = Kanrisuru::Mode::Permission.new(7, 'rwx')
#<Kanrisuru::Mode::Permission:0x00007f8a8292a018 @executable=true, @numeric=7, @readable=true, @symbolic="rwx", @writeable=true>
Public Instance Methods
to_i
Returns the numeric representation of the permission as an integer.
permission = Kanrisuru::Mode::Permission.new(6, 'rw-')
permission.to_i
6
to_s
Returns the symoblic representation of the permission as a string.
permission = Kanrisuru::Mode::Permission.new(5, 'r-x')
permission.to_s
'r-x'
all?
Returns if all bits, read, write and execute, are set to true
permission = Kanrisuru::Mode::Permission.new(7, 'rwx')
permission.all?
true
numeric
Get the numeric representation of the permission bits.
permission = Kanrisuru::Mode::Permission.new(5, 'r-x')
permission.numeric
"5"
numeric=
Set the permission bits with a numeric value.
permission = Kanrisuru::Mode::Permission.new(0, '---')
permission.numeric = "1"
permission.symbolic
'--x'
permission.numeric = "7"
permission.all?
true
symbolic
Get the symbolic represenation of the permission bits.
permission = Kanrisuru::Mode::Permission.new(5, 'r-x')
permission.symbolic
'r-x'
symbolic=
Set the permission bits with a symbolic value.
permission = Kanrisuru::Mode::Permission.new(1, '--x')
permission.symbolic = 'rwx'
permission.numeric
"7"
read=
Set the read permission bit. Can be true or false.
permission = Kanrisuru::Mode::Permission.new(2, '-w-')
permission.read = true
permission.symbolic
'rw-'
read?
Returns if the read permission bit is set or not.
permission = Kanrisurur::Mode::Permission.new(4, 'r--')
permission.read?
true
write=
Set the write permission bit. Can be true or false.
permission = Kanrisuru::Mode::Permission.new(0, '---')
permission.write = true
permission.symbolic
'-w-'
write?
Returns if the write permission bit is set or not.
permission = Kanrisuru::Mode::Permission.new(6, 'rw-')
permission.write?
true
execute=
Set the execute permission bit. Can be true or false
permission = Kanrisuru::Mode::Permission.new(4, 'r--')
permission.execute = true
permission.symbolic
'r-x'
execute?
Returns if the execute permission bit is set or not.
permission = Kanrisuru::Mode::Permission.new(5, 'r-x')
permission.execute?
true