Class: GodObject::FilePermissions::SpecialMode

Inherits:
Object
  • Object
show all
Extended by:
Forwardable, ModeMixin::ClassMethods
Includes:
BitSet, Comparable, ModeMixin
Defined in:
lib/god_object/file_permissions/special_mode.rb

Overview

Represents one component of the normal file mode in POSIX environments.

The SpecialMode is basically an immutable bit set consisting of the digits :setuid, :setgid and :sticky.

Constant Summary collapse

PATTERN =

Regular expression for parsing a SpecialMode from a String representation.

/^#{blank}(?:#{digit_mode}|#{octal_mode})#{blank}$/
BIT_SET_CONFIGURATION =

Configuration for the GodObject:::BitSet object which is used to handle the state internally.

Configuration.new(
  setuid: 's',
  setgid: 's',
  sticky: 't'
)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(numeric) ⇒ void #initialize(enabled_digits) ⇒ void

Initializes a new SpecialMode

Overloads:

  • #initialize(numeric) ⇒ void

    Parameters:

    • numeric (Integer)

      a numeric representation

  • #initialize(enabled_digits) ⇒ void

    Parameters:

    • enabled_digits (Array<:setuid, :setgid, :sticky>)

      a list of enabled digits



88
89
90
# File 'lib/god_object/file_permissions/special_mode.rb', line 88

def initialize(*mode_components)
  @bit_set = BIT_SET_CONFIGURATION.new(*mode_components)
end

Instance Attribute Details

#disabled_digitsSet<:setuid, :setgid, :sticky> (readonly)

Returns a list of all digits which are disabled.

Returns:

  • (Set<:setuid, :setgid, :sticky>)

    a list of all digits which are disabled



141
142
143
144
# File 'lib/god_object/file_permissions/special_mode.rb', line 141

def_delegators :@bit_set,
:attributes, :state, :[], :enabled_digits, :disabled_digits,
:setuid?, :setuid, :setgid?, :setgid, :sticky?, :sticky,
:to_i, :to_s, :hash

#enabled_digitsSet<:setuid, :setgid, :sticky> (readonly)

Returns a list of all digits which are enabled.

Returns:

  • (Set<:setuid, :setgid, :sticky>)

    a list of all digits which are enabled



141
142
143
144
# File 'lib/god_object/file_permissions/special_mode.rb', line 141

def_delegators :@bit_set,
:attributes, :state, :[], :enabled_digits, :disabled_digits,
:setuid?, :setuid, :setgid?, :setgid, :sticky?, :sticky,
:to_i, :to_s, :hash

#setgid?true, false (readonly) Also known as: setgid

Returns the current state of the setgid digit.

Returns:

  • (true, false)

    the current state of the setgid digit



141
142
143
144
# File 'lib/god_object/file_permissions/special_mode.rb', line 141

def_delegators :@bit_set,
:attributes, :state, :[], :enabled_digits, :disabled_digits,
:setuid?, :setuid, :setgid?, :setgid, :sticky?, :sticky,
:to_i, :to_s, :hash

#setuid?true, false (readonly) Also known as: setuid

Returns the current state of the setuid digit.

Returns:

  • (true, false)

    the current state of the setuid digit



141
142
143
144
# File 'lib/god_object/file_permissions/special_mode.rb', line 141

def_delegators :@bit_set,
:attributes, :state, :[], :enabled_digits, :disabled_digits,
:setuid?, :setuid, :setgid?, :setgid, :sticky?, :sticky,
:to_i, :to_s, :hash

#state{(:read, :write, :execute) => true, false} (readonly)

Returns a table of all digits and their states.

Returns:

  • ({(:read, :write, :execute) => true, false})

    a table of all digits and their states



141
142
143
144
# File 'lib/god_object/file_permissions/special_mode.rb', line 141

def_delegators :@bit_set,
:attributes, :state, :[], :enabled_digits, :disabled_digits,
:setuid?, :setuid, :setgid?, :setgid, :sticky?, :sticky,
:to_i, :to_s, :hash

#sticky?true, false (readonly) Also known as: sticky

Returns the current state of the sticky digit.

Returns:

  • (true, false)

    the current state of the sticky digit



141
142
143
144
# File 'lib/god_object/file_permissions/special_mode.rb', line 141

def_delegators :@bit_set,
:attributes, :state, :[], :enabled_digits, :disabled_digits,
:setuid?, :setuid, :setgid?, :setgid, :sticky?, :sticky,
:to_i, :to_s, :hash

Class Method Details

#build(mode) ⇒ GodObject::FilePermissions::ModeMixin #build(string) ⇒ GodObject::FilePermissions::ModeMixin #build(numeric) ⇒ GodObject::FilePermissions::ModeMixin #build(enabled_digits) ⇒ GodObject::FilePermissions::ModeMixin Originally defined in module ModeMixin::ClassMethods

Either passes through or generates a new Mode object

Overloads:

Returns:

.parse(string) ⇒ GodObject::FilePermissions::SpecialMode

Creates a new SpecialMode object by parsing a String representation.

Parameters:

  • string (String)

    a String containing a mode

Returns:



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/god_object/file_permissions/special_mode.rb', line 58

def parse(string)
  result = string.match(PATTERN)

  case
  when !result
    raise ParserError, 'Invalid format'
  when result[:octal_mode]
    new(result[:octal_mode].to_i)
  else
    mode_components = []

    mode_components << :setuid if result[:digit_mode][0] == 's'
    mode_components << :setgid if result[:digit_mode][1] == 's'
    mode_components << :sticky if result[:digit_mode][2] == 't'

    new(mode_components)
  end
end

Instance Method Details

#+(other) ⇒ GodObject::FilePermissions::ModeMixin Originally defined in module ModeMixin

Returns a new Mode with the enabled digits of the current and other.

Parameters:

Returns:

#<=>(other) ⇒ -1, ... Originally defined in module ModeMixin

Note:

Only other Modes or Integer-likes are considered comparable.

Compares the Mode to another to determine its relative position.

Relative position is defined by comparing the Integer representation.

Parameters:

  • other (Object)

    other Object to be compared object

Returns:

  • (-1, 0, 1, nil)

    -1 if other is greater, 0 if other is equal and 1 if other is lesser than self, nil if comparison is impossible

#[](digit) ⇒ true, false

Returns current state of the given digit.

Parameters:

  • digit (:setuid, :setgid, :sticky, Integer)

    name or index of a digit

Returns:

  • (true, false)

    current state of the given digit



141
142
143
144
# File 'lib/god_object/file_permissions/special_mode.rb', line 141

def_delegators :@bit_set,
:attributes, :state, :[], :enabled_digits, :disabled_digits,
:setuid?, :setuid, :setgid?, :setgid, :sticky?, :sticky,
:to_i, :to_s, :hash

#difference(other) ⇒ GodObject::FilePermissions::ModeMixin Also known as: - Originally defined in module ModeMixin

Returns a new Mode with the enabled digits of the current without the enabled digits of other.

Parameters:

Returns:

#eql?(other) ⇒ true, false Originally defined in module ModeMixin

Answers if another object is equal and of the same type family.

Parameters:

  • other (Object)

    an object to be checked for equality

Returns:

  • (true, false)

    true if the object is considered equal and of the same type family, false otherwise

See Also:

#hashsee Object#hash

Returns identity hash for hash table usage.

Returns:

  • (see Object#hash)

    identity hash for hash table usage



141
142
143
144
# File 'lib/god_object/file_permissions/special_mode.rb', line 141

def_delegators :@bit_set,
:attributes, :state, :[], :enabled_digits, :disabled_digits,
:setuid?, :setuid, :setgid?, :setgid, :sticky?, :sticky,
:to_i, :to_s, :hash

#inspectString Originally defined in module ModeMixin

Represents a Mode as String for debugging.

Returns:

  • (String)

    a String representation for debugging

#intersection(other) ⇒ GodObject::FilePermissions::ModeMixin Also known as: & Originally defined in module ModeMixin

Returns a new Mode with only those digits enabled which are enabled in both the current and other.

Parameters:

Returns:

#invertGodObject::FilePermissions::ModeMixin Originally defined in module ModeMixin

Returns a new Mode with all digit states inverted.

Returns:

#symmetric_difference(other) ⇒ GodObject::FilePermissions::ModeMixin Also known as: ^ Originally defined in module ModeMixin

Returns a new Mode with the enabled digits which are enabled in only one of current and other.

Parameters:

Returns:

#to_iInteger

Represents a SpecialMode as a binary Integer.

Returns:

  • (Integer)

    an Integer representation



141
142
143
144
# File 'lib/god_object/file_permissions/special_mode.rb', line 141

def_delegators :@bit_set,
:attributes, :state, :[], :enabled_digits, :disabled_digits,
:setuid?, :setuid, :setgid?, :setgid, :sticky?, :sticky,
:to_i, :to_s, :hash

#to_s(format) ⇒ String

Represents a SpecialMode as String.

Parameters:

  • format (:long, :short)

    the String format

Returns:

  • (String)

    a String representation



141
142
143
144
# File 'lib/god_object/file_permissions/special_mode.rb', line 141

def_delegators :@bit_set,
:attributes, :state, :[], :enabled_digits, :disabled_digits,
:setuid?, :setuid, :setgid?, :setgid, :sticky?, :sticky,
:to_i, :to_s, :hash

#union(other) ⇒ GodObject::FilePermissions::ModeMixin Also known as: | Originally defined in module ModeMixin

Returns a new Mode with the enabled digits of the current and other.

Parameters:

Returns: