Module: GodObject::FilePermissions::ModeMixin

Included in:
Mode, SpecialMode
Defined in:
lib/god_object/file_permissions/mode_mixin.rb

Overview

Common functionality of both Mode and SpecialMode

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#+(other) ⇒ GodObject::FilePermissions::ModeMixin

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

Parameters:

Returns:



74
75
76
77
78
# 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) ⇒ -1, ...

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



138
139
140
141
142
# File 'lib/god_object/file_permissions/mode_mixin.rb', line 138

def <=>(other)
  to_i <=> other.to_i
rescue NoMethodError
  nil
end

#difference(other) ⇒ GodObject::FilePermissions::ModeMixin Also known as: -

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

Parameters:

Returns:



96
97
98
99
100
# 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

#eql?(other) ⇒ true, false

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:



150
151
152
# File 'lib/god_object/file_permissions/mode_mixin.rb', line 150

def eql?(other)
  self == other && other.kind_of?(self.class)
end

#inspectString

Represents a Mode as String for debugging.

Returns:

  • (String)

    a String representation for debugging



157
158
159
# File 'lib/god_object/file_permissions/mode_mixin.rb', line 157

def inspect
  "#<#{self.class}: #{to_s.inspect}>"
end

#intersection(other) ⇒ GodObject::FilePermissions::ModeMixin Also known as: &

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

Parameters:

Returns:



108
109
110
111
112
# 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

#invertGodObject::FilePermissions::ModeMixin

Returns a new Mode with all digit states inverted.

Returns:



66
67
68
# File 'lib/god_object/file_permissions/mode_mixin.rb', line 66

def invert
  self.class.new(disabled_digits)
end

#symmetric_difference(other) ⇒ GodObject::FilePermissions::ModeMixin Also known as: ^

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

Parameters:

Returns:



120
121
122
123
124
# 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

#union(other) ⇒ GodObject::FilePermissions::ModeMixin Also known as: |

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

Parameters:

Returns:



84
85
86
87
88
# 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