class DataMetaXtra::FileSys::Perm
A set of permissions: any mix of read, write and execute, including all set to false. @!attribute [rw] r
@return [Boolean] read access, true or false
@!attribute [rw] w
@return [Boolean] write access, true or false
@!attribute [rw] w
@return [Boolean] execute access, true or false
Constants
- ALL
Convenient instance - all perms
- EXEC_MASK
POSIX Execute permission mask: binary 1
- GROUP_ID_EXE_MASK
Unix
S_ISGID
flag defined in {pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_stat.h.html sys/stat.h} which sets the owner's ID on executable regardless of who actually activates the executable. See {en.wikipedia.org/wiki/Setuid this article for details.}- NONE
Convenient instance - no perms
- R
Convenient instance - read only
- READ_MASK
POSIX Read permission mask: binary 100
- RW
Convenient instance - read/write
- RX
Convenient instance - read and exec
- STICKY_MASK
Unix {en.wikipedia.org/wiki/Sticky_bit Sticky bit}, the
S_ISVTX
mask (orS_ISTXT
in BSD) defined in {pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_stat.h.html sys/stat.h}. Use with caution because the semantics is fuzzy and, by some is considered obsolete.- USER_ID_EXE_MASK
Unix
S_ISUID
flag defined in {pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_stat.h.html sys/stat.h} which sets the owner's ID on executable regardless of who actually activates the executable. See {en.wikipedia.org/wiki/Setuid this article for details.}- W
Convenient instance - write only
- WRITE_MASK
POSIX Write permission mask: binary 010
Attributes
Public Class Methods
# File lib/dataMetaXtra/fileSys.rb, line 67 def initialize(r, w, x) @r, @w, @x = r, w, x end
Creates an instance from textual specification, up to tree letters r
, w
, x
in any order, 'r
' for 'read', 'w
' for 'write', 'x
' for 'execute. Letter present turns the setting on, letter absent turns it off. @param [String] specs String of letters as described or a Fixnum with usual Posix bitmask: 4 for read, 2 for write, 1 for exec. @raise [ArgumentError] if the specs contain invalid character when specified as a String or if it does not fall into the range
between 0 and 7 inclusively if passed as a Fixnum
@return [Perm] instance per the specs
# File lib/dataMetaXtra/fileSys.rb, line 94 def self.of(specs) result = Perm.new(false, false, false) case when specs.kind_of?(String) specs.each_char { |c| case c when 'r' result.r = true when 'w' result.w = true when 'x' result.x = true else raise ArgumentError, %<Illegal perms letter "#{c}" in the string of "#{specs}"> end } when specs.kind_of?(Fixnum) raise ArgumentError, %<Illegal perm mask value of #{specs}> if specs < 0 || specs > 7 result.r = true if specs & READ_MASK != 0 result.w = true if specs & WRITE_MASK != 0 result.x = true if specs & EXEC_MASK != 0 else raise ArgumentError, %<Illegal specs: "#{specs.inspect}"> end result end
Public Instance Methods
Redefine equality operator for simple comparison, not delegated to {#eql?}, code simply repeated here for speed
# File lib/dataMetaXtra/fileSys.rb, line 82 def ==(other) self.r == other.r && self.w == other.w && self.x == other.x end
Standard Ruby object equality method for hashes and sets.
# File lib/dataMetaXtra/fileSys.rb, line 74 def eql?(other) self.r == other.r && self.w == other.w && self.x == other.x end
Turns the permission into the 'rwx' format for brevity and serialization
# File lib/dataMetaXtra/fileSys.rb, line 124 def toRwx result = '' result << 'r' if r result << 'w' if w result << 'x' if x result end
Turns the permission into the bitmask format for brevity and serialization
# File lib/dataMetaXtra/fileSys.rb, line 136 def to_i result = 0 result |= READ_MASK if r result |= WRITE_MASK if w result |= EXEC_MASK if x result end