Class: GodObject::FilePermissions::Mode
- Inherits:
-
Object
- Object
- GodObject::FilePermissions::Mode
- Extended by:
- Forwardable, GodObject::FilePermissions::ModeMixin::ClassMethods
- Includes:
- BitSet, Comparable, ModeMixin
- Defined in:
- lib/god_object/file_permissions/mode.rb
Overview
Represents one component of the normal file mode in POSIX environments.
The Mode is basically an immutable bit set consisting of the digits :read, :write and :execute.
Constant Summary collapse
- PATTERN =
Regular expression for parsing a Mode 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( read: 'r', write: 'w', execute: 'x' )
Instance Attribute Summary collapse
-
#disabled_digits ⇒ Set<:read, :write, :execute>
readonly
A list of all digits which are disabled.
-
#enabled_digits ⇒ Set<:read, :write, :execute>
readonly
A list of all digits which are enabled.
-
#execute? ⇒ true, false
(also: #execute)
readonly
The current state of the execute digit.
-
#read? ⇒ true, false
(also: #read)
readonly
The current state of the read digit.
-
#state ⇒ {(:read, :write, :execute) => true, false}
(also: #attributes)
readonly
A table of all digits and their states.
-
#write? ⇒ true, false
(also: #write)
readonly
The current state of the write digit.
Class Method Summary collapse
-
.build(mode) ⇒ GodObject::FilePermissions::ModeMixin
extended
from GodObject::FilePermissions::ModeMixin::ClassMethods
Either passes through or generates a new Mode object.
-
.parse(string) ⇒ GodObject::FilePermissions::Mode
Creates a new Mode 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 Mode.
-
#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 Mode as a binary Integer.
-
#to_s(format) ⇒ String
Represents a Mode 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 Mode
93 94 95 |
# File 'lib/god_object/file_permissions/mode.rb', line 93 def initialize(*mode_components) @bit_set = BIT_SET_CONFIGURATION.new(*mode_components) end |
Instance Attribute Details
#disabled_digits ⇒ Set<:read, :write, :execute> (readonly)
Returns a list of all digits which are disabled.
148 149 150 151 |
# File 'lib/god_object/file_permissions/mode.rb', line 148 def_delegators :@bit_set, :attributes, :state, :[], :enabled_digits, :disabled_digits, :read?, :read, :write?, :write, :execute?, :execute, :to_i, :to_s, :hash |
#enabled_digits ⇒ Set<:read, :write, :execute> (readonly)
Returns a list of all digits which are enabled.
148 149 150 151 |
# File 'lib/god_object/file_permissions/mode.rb', line 148 def_delegators :@bit_set, :attributes, :state, :[], :enabled_digits, :disabled_digits, :read?, :read, :write?, :write, :execute?, :execute, :to_i, :to_s, :hash |
#execute? ⇒ true, false (readonly) Also known as: execute
Returns the current state of the execute digit.
148 149 150 151 |
# File 'lib/god_object/file_permissions/mode.rb', line 148 def_delegators :@bit_set, :attributes, :state, :[], :enabled_digits, :disabled_digits, :read?, :read, :write?, :write, :execute?, :execute, :to_i, :to_s, :hash |
#read? ⇒ true, false (readonly) Also known as: read
Returns the current state of the read digit.
148 149 150 151 |
# File 'lib/god_object/file_permissions/mode.rb', line 148 def_delegators :@bit_set, :attributes, :state, :[], :enabled_digits, :disabled_digits, :read?, :read, :write?, :write, :execute?, :execute, :to_i, :to_s, :hash |
#state ⇒ {(:read, :write, :execute) => true, false} (readonly) Also known as: attributes
Returns a table of all digits and their states.
148 149 150 151 |
# File 'lib/god_object/file_permissions/mode.rb', line 148 def_delegators :@bit_set, :attributes, :state, :[], :enabled_digits, :disabled_digits, :read?, :read, :write?, :write, :execute?, :execute, :to_i, :to_s, :hash |
#write? ⇒ true, false (readonly) Also known as: write
Returns the current state of the write digit.
148 149 150 151 |
# File 'lib/god_object/file_permissions/mode.rb', line 148 def_delegators :@bit_set, :attributes, :state, :[], :enabled_digits, :disabled_digits, :read?, :read, :write?, :write, :execute?, :execute, :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 GodObject::FilePermissions::ModeMixin::ClassMethods
Either passes through or generates a new Mode object
.parse(string) ⇒ GodObject::FilePermissions::Mode
Creates a new Mode object by parsing a String representation.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/god_object/file_permissions/mode.rb', line 56 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 = [] result[:digit_mode].scan(/r|w|x/).each do |digit| mode_components << :read if digit == 'r' mode_components << :write if digit == 'w' mode_components << :execute if digit == 'x' end if mode_components.uniq! raise ParserError, "Duplicate digit in: #{string.inspect}" end 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.
148 149 150 151 |
# File 'lib/god_object/file_permissions/mode.rb', line 148 def_delegators :@bit_set, :attributes, :state, :[], :enabled_digits, :disabled_digits, :read?, :read, :write?, :write, :execute?, :execute, :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.
148 149 150 151 |
# File 'lib/god_object/file_permissions/mode.rb', line 148 def_delegators :@bit_set, :attributes, :state, :[], :enabled_digits, :disabled_digits, :read?, :read, :write?, :write, :execute?, :execute, :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 Mode as a binary Integer.
148 149 150 151 |
# File 'lib/god_object/file_permissions/mode.rb', line 148 def_delegators :@bit_set, :attributes, :state, :[], :enabled_digits, :disabled_digits, :read?, :read, :write?, :write, :execute?, :execute, :to_i, :to_s, :hash |
#to_s(format) ⇒ String
Represents a Mode as String.
148 149 150 151 |
# File 'lib/god_object/file_permissions/mode.rb', line 148 def_delegators :@bit_set, :attributes, :state, :[], :enabled_digits, :disabled_digits, :read?, :read, :write?, :write, :execute?, :execute, :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.