Class: GodObject::FilePermissions::SpecialMode
- Inherits:
-
Object
- Object
- GodObject::FilePermissions::SpecialMode
- 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
-
#disabled_digits ⇒ Set<:setuid, :setgid, :sticky>
readonly
A list of all digits which are disabled.
-
#enabled_digits ⇒ Set<:setuid, :setgid, :sticky>
readonly
A list of all digits which are enabled.
-
#setgid? ⇒ true, false
(also: #setgid)
readonly
The current state of the setgid digit.
-
#setuid? ⇒ true, false
(also: #setuid)
readonly
The current state of the setuid digit.
-
#state ⇒ {(:read, :write, :execute) => true, false}
readonly
A table of all digits and their states.
-
#sticky? ⇒ true, false
(also: #sticky)
readonly
The current state of the sticky digit.
Class Method Summary collapse
-
.build(mode) ⇒ GodObject::FilePermissions::ModeMixin
extended
from ModeMixin::ClassMethods
Either passes through or generates a new Mode object.
-
.parse(string) ⇒ GodObject::FilePermissions::SpecialMode
Creates a new SpecialMode object by parsing a String representation.
Instance Method Summary collapse
-
#+(other) ⇒ GodObject::FilePermissions::ModeMixin
included
from ModeMixin
A new Mode with the enabled digits of the current and other.
-
#<=>(other) ⇒ -1, ...
included
from ModeMixin
Compares the Mode to another to determine its relative position.
-
#[](digit) ⇒ true, false
Current state of the given digit.
-
#difference(other) ⇒ GodObject::FilePermissions::ModeMixin
(also: #-)
included
from ModeMixin
A new Mode with the enabled digits of the current without the enabled digits of other.
-
#eql?(other) ⇒ true, false
included
from ModeMixin
Answers if another object is equal and of the same type family.
-
#hash ⇒ see Object#hash
Identity hash for hash table usage.
-
#initialize(*mode_components) ⇒ void
constructor
Initializes a new SpecialMode.
-
#inspect ⇒ String
included
from ModeMixin
Represents a Mode as String for debugging.
-
#intersection(other) ⇒ GodObject::FilePermissions::ModeMixin
(also: #&)
included
from ModeMixin
A new Mode with only those digits enabled which are enabled in both the current and other.
-
#invert ⇒ GodObject::FilePermissions::ModeMixin
included
from ModeMixin
A new Mode with all digit states inverted.
-
#symmetric_difference(other) ⇒ GodObject::FilePermissions::ModeMixin
(also: #^)
included
from ModeMixin
A new Mode with the enabled digits which are enabled in only one of current and other.
-
#to_i ⇒ Integer
Represents a SpecialMode as a binary Integer.
-
#to_s(format) ⇒ String
Represents a SpecialMode as String.
-
#union(other) ⇒ GodObject::FilePermissions::ModeMixin
(also: #|)
included
from ModeMixin
A new Mode with the enabled digits of the current and other.
Constructor Details
#initialize(numeric) ⇒ void #initialize(enabled_digits) ⇒ void
Initializes a new SpecialMode
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_digits ⇒ Set<:setuid, :setgid, :sticky> (readonly)
Returns 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_digits ⇒ Set<:setuid, :setgid, :sticky> (readonly)
Returns 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.
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.
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.
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.
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
.parse(string) ⇒ GodObject::FilePermissions::SpecialMode
Creates a new SpecialMode object by parsing a String representation.
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.
#<=>(other) ⇒ -1, ... Originally defined in module ModeMixin
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.
#[](digit) ⇒ true, false
Returns 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.
#eql?(other) ⇒ true, false Originally defined in module ModeMixin
Answers if another object is equal and of the same type family.
#hash ⇒ see Object#hash
Returns 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 |
#inspect ⇒ String Originally defined in module ModeMixin
Represents a Mode as String 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.
#invert ⇒ GodObject::FilePermissions::ModeMixin Originally defined in module ModeMixin
Returns a new Mode with all digit states inverted.
#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.
#to_i ⇒ Integer
Represents a SpecialMode as a binary Integer.
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.
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.