module GodObject::FilePermissions::ModeMixin

Common functionality of both Mode and SpecialMode

Public Class Methods

included(base) click to toggle source

Hook for automatic inclusion of the ClassMethods mixin @private

# File lib/god_object/file_permissions/mode_mixin.rb, line 28
def self.included(base)
  base.extend ClassMethods
end

Public Instance Methods

&(other)
Alias for: intersection
+(other) click to toggle source

@param [GodObject::FilePermissions::ModeMixin, Array<Symbol>] other

another Mode

@return [GodObject::FilePermissions::ModeMixin] a new Mode with the

enabled digits of the current and other
# File lib/god_object/file_permissions/mode_mixin.rb, line 74
def +(other)
  other = other.enabled_digits if other.respond_to?(:enabled_digits)

  self.class.new(enabled_digits + other)
end
-(other)
Alias for: difference
<=>(other) click to toggle source

Compares the Mode to another to determine its relative position.

Relative position is defined by comparing the Integer representation.

@note Only other Modes or Integer-likes are considered comparable.

@param [Object] other other Object to be compared

object

@return [-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
# File lib/god_object/file_permissions/mode_mixin.rb, line 138
def <=>(other)
  to_i <=> other.to_i
rescue NoMethodError
  nil
end
^(other)
difference(other) click to toggle source

@param [GodObject::FilePermissions::ModeMixin, Array<Symbol>] other

another Mode

@return [GodObject::FilePermissions::ModeMixin] a new Mode with the

enabled digits of the current without the enabled digits of other
# File lib/god_object/file_permissions/mode_mixin.rb, line 96
def difference(other)
  other = other.enabled_digits if other.respond_to?(:enabled_digits)

  self.class.new(enabled_digits - other)
end
Also aliased as: -
eql?(other) click to toggle source

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

@see GodObject::FilePermissions::ModeMixin#<=> @param [Object] other an object to be checked for equality @return [true, false] true if the object is considered equal and of the

same type family, false otherwise
# File lib/god_object/file_permissions/mode_mixin.rb, line 150
def eql?(other)
  self == other && other.kind_of?(self.class)
end
inspect() click to toggle source

Represents a Mode as String for debugging.

@return [String] a String representation for debugging

# File lib/god_object/file_permissions/mode_mixin.rb, line 157
def inspect
  "#<#{self.class}: #{to_s.inspect}>"
end
intersection(other) click to toggle source

@param [GodObject::FilePermissions::ModeMixin, Integer] other another

Mode

@return [GodObject::FilePermissions::ModeMixin] a new Mode with only

those digits enabled which are enabled in both the current and other
# File lib/god_object/file_permissions/mode_mixin.rb, line 108
def intersection(other)
  other = other.to_i if other.respond_to?(:to_i)

  self.class.new(to_i & other)
end
Also aliased as: &
invert() click to toggle source

@return [GodObject::FilePermissions::ModeMixin] a new Mode with all

digit states inverted
# File lib/god_object/file_permissions/mode_mixin.rb, line 66
def invert
  self.class.new(disabled_digits)
end
symmetric_difference(other) click to toggle source

@param [GodObject::FilePermissions::ModeMixin, Integer] other another

Mode

@return [GodObject::FilePermissions::ModeMixin] a new Mode with the

enabled digits which are enabled in only one of current and other
# File lib/god_object/file_permissions/mode_mixin.rb, line 120
def symmetric_difference(other)
  other = other.to_i if other.respond_to?(:to_i)

  self.class.new(to_i ^ other)
end
Also aliased as: ^
union(other) click to toggle source

@param [GodObject::FilePermissions::ModeMixin, Integer] other another

Mode

@return [GodObject::FilePermissions::ModeMixin] a new Mode with the

enabled digits of the current and other
# File lib/god_object/file_permissions/mode_mixin.rb, line 84
def union(other)
  other = other.to_i if other.respond_to?(:to_i)

  self.class.new(to_i | other)
end
Also aliased as: |
|(other)
Alias for: union