Class: DataMetaXtra::FileSys::PosixPerms

Inherits:
Object
  • Object
show all
Defined in:
lib/dataMetaXtra/fileSys.rb

Overview

POSIX access perms - per system, user, group and world

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, group, world, sys = nil) ⇒ PosixPerms

Creates an instance

Parameters:



223
224
225
226
227
228
# File 'lib/dataMetaXtra/fileSys.rb', line 223

def initialize(user, group, world, sys = nil)
    @u = PosixPerms.from(user, 'user')
    @g = PosixPerms.from(group, 'group')
    @a = PosixPerms.from(world, 'world')
    @s = PosixPerms.from(sys, 'system')
end

Instance Attribute Details

#aPerm

Returns world perms (all).

Returns:

  • (Perm)

    world perms (all)



194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# File 'lib/dataMetaXtra/fileSys.rb', line 194

class PosixPerms
    attr_accessor :s, :u, :g, :a
=begin rdoc
Parses the {Perm} instance from the given source.

@param [String] source either a String or a Fixnum a {Perm} or +nil+, see the method {Perm.of} for details.
@param [String] kind the kind of the permissions for diagnostics, like 'user', 'group', 'world' or 'system'
@return [Perm] instance according to the description
@raise [ArgumentError] if the specs contain invalid character in case of a String or if the source is neither
    a String nor a {Perm} nor +nil+
=end
    def self.from(source, kind)
        case
            when source.kind_of?(NilClass) || source.kind_of?(Perm)
                source
            when source.kind_of?(String) || source.kind_of?(Fixnum)
                Perm.of(source)
            else
                raise ArgumentError, %<For #{kind} perms, invalid perm source: #{source.inspect} >
        end
    end

=begin rdoc
Creates an instance
@param [String] user user permissions, can be passed as {Perm} object or String or Fixnum, see the method {PosixPerms.from} for details.
@param [String] group group permissions, can be passed as {Perm} object or String or Fixnum, see the method {PosixPerms.from} for details.
@param [String] world world permissions, can be passed as {Perm} object or String or Fixnum, see the method {PosixPerms.from} for details.
@param [String] sticky flag, can be passed as {Perm} object or String or Fixnum, see the method {PosixPerms.from} for details.
=end
    def initialize(user, group, world, sys = nil)
        @u = PosixPerms.from(user, 'user')
        @g = PosixPerms.from(group, 'group')
        @a = PosixPerms.from(world, 'world')
        @s = PosixPerms.from(sys, 'system')
    end

=begin rdoc
Standard Ruby object equality method for hashes and sets.
=end
    def eql?(other)
        self.u == other.u && self.g == other.g && self.a == other.a && self.s == other.s
    end
=begin rdoc
Redefine equality operator for simple comparison, not delegated to {#eql?}, code simply repeated here
for speed
=end
    def ==(other)
        self.u == other.u && self.g == other.g && self.a == other.a && self.s == other.s
    end

=begin
Converts to integer POSIX specification, 3 bits per each of User, Group, All aka World aka Others
=end
    def to_i; ('%d%d%d' % [@u, @g, @a]).to_i(8) end

end

#gPerm

Returns group perms.

Returns:

  • (Perm)

    group perms



194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# File 'lib/dataMetaXtra/fileSys.rb', line 194

class PosixPerms
    attr_accessor :s, :u, :g, :a
=begin rdoc
Parses the {Perm} instance from the given source.

@param [String] source either a String or a Fixnum a {Perm} or +nil+, see the method {Perm.of} for details.
@param [String] kind the kind of the permissions for diagnostics, like 'user', 'group', 'world' or 'system'
@return [Perm] instance according to the description
@raise [ArgumentError] if the specs contain invalid character in case of a String or if the source is neither
    a String nor a {Perm} nor +nil+
=end
    def self.from(source, kind)
        case
            when source.kind_of?(NilClass) || source.kind_of?(Perm)
                source
            when source.kind_of?(String) || source.kind_of?(Fixnum)
                Perm.of(source)
            else
                raise ArgumentError, %<For #{kind} perms, invalid perm source: #{source.inspect} >
        end
    end

=begin rdoc
Creates an instance
@param [String] user user permissions, can be passed as {Perm} object or String or Fixnum, see the method {PosixPerms.from} for details.
@param [String] group group permissions, can be passed as {Perm} object or String or Fixnum, see the method {PosixPerms.from} for details.
@param [String] world world permissions, can be passed as {Perm} object or String or Fixnum, see the method {PosixPerms.from} for details.
@param [String] sticky flag, can be passed as {Perm} object or String or Fixnum, see the method {PosixPerms.from} for details.
=end
    def initialize(user, group, world, sys = nil)
        @u = PosixPerms.from(user, 'user')
        @g = PosixPerms.from(group, 'group')
        @a = PosixPerms.from(world, 'world')
        @s = PosixPerms.from(sys, 'system')
    end

=begin rdoc
Standard Ruby object equality method for hashes and sets.
=end
    def eql?(other)
        self.u == other.u && self.g == other.g && self.a == other.a && self.s == other.s
    end
=begin rdoc
Redefine equality operator for simple comparison, not delegated to {#eql?}, code simply repeated here
for speed
=end
    def ==(other)
        self.u == other.u && self.g == other.g && self.a == other.a && self.s == other.s
    end

=begin
Converts to integer POSIX specification, 3 bits per each of User, Group, All aka World aka Others
=end
    def to_i; ('%d%d%d' % [@u, @g, @a]).to_i(8) end

end

#sPerm

Returns Sticky flag.

Returns:

  • (Perm)

    Sticky flag



194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# File 'lib/dataMetaXtra/fileSys.rb', line 194

class PosixPerms
    attr_accessor :s, :u, :g, :a
=begin rdoc
Parses the {Perm} instance from the given source.

@param [String] source either a String or a Fixnum a {Perm} or +nil+, see the method {Perm.of} for details.
@param [String] kind the kind of the permissions for diagnostics, like 'user', 'group', 'world' or 'system'
@return [Perm] instance according to the description
@raise [ArgumentError] if the specs contain invalid character in case of a String or if the source is neither
    a String nor a {Perm} nor +nil+
=end
    def self.from(source, kind)
        case
            when source.kind_of?(NilClass) || source.kind_of?(Perm)
                source
            when source.kind_of?(String) || source.kind_of?(Fixnum)
                Perm.of(source)
            else
                raise ArgumentError, %<For #{kind} perms, invalid perm source: #{source.inspect} >
        end
    end

=begin rdoc
Creates an instance
@param [String] user user permissions, can be passed as {Perm} object or String or Fixnum, see the method {PosixPerms.from} for details.
@param [String] group group permissions, can be passed as {Perm} object or String or Fixnum, see the method {PosixPerms.from} for details.
@param [String] world world permissions, can be passed as {Perm} object or String or Fixnum, see the method {PosixPerms.from} for details.
@param [String] sticky flag, can be passed as {Perm} object or String or Fixnum, see the method {PosixPerms.from} for details.
=end
    def initialize(user, group, world, sys = nil)
        @u = PosixPerms.from(user, 'user')
        @g = PosixPerms.from(group, 'group')
        @a = PosixPerms.from(world, 'world')
        @s = PosixPerms.from(sys, 'system')
    end

=begin rdoc
Standard Ruby object equality method for hashes and sets.
=end
    def eql?(other)
        self.u == other.u && self.g == other.g && self.a == other.a && self.s == other.s
    end
=begin rdoc
Redefine equality operator for simple comparison, not delegated to {#eql?}, code simply repeated here
for speed
=end
    def ==(other)
        self.u == other.u && self.g == other.g && self.a == other.a && self.s == other.s
    end

=begin
Converts to integer POSIX specification, 3 bits per each of User, Group, All aka World aka Others
=end
    def to_i; ('%d%d%d' % [@u, @g, @a]).to_i(8) end

end

#uPerm

Returns user perms.

Returns:

  • (Perm)

    user perms



194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# File 'lib/dataMetaXtra/fileSys.rb', line 194

class PosixPerms
    attr_accessor :s, :u, :g, :a
=begin rdoc
Parses the {Perm} instance from the given source.

@param [String] source either a String or a Fixnum a {Perm} or +nil+, see the method {Perm.of} for details.
@param [String] kind the kind of the permissions for diagnostics, like 'user', 'group', 'world' or 'system'
@return [Perm] instance according to the description
@raise [ArgumentError] if the specs contain invalid character in case of a String or if the source is neither
    a String nor a {Perm} nor +nil+
=end
    def self.from(source, kind)
        case
            when source.kind_of?(NilClass) || source.kind_of?(Perm)
                source
            when source.kind_of?(String) || source.kind_of?(Fixnum)
                Perm.of(source)
            else
                raise ArgumentError, %<For #{kind} perms, invalid perm source: #{source.inspect} >
        end
    end

=begin rdoc
Creates an instance
@param [String] user user permissions, can be passed as {Perm} object or String or Fixnum, see the method {PosixPerms.from} for details.
@param [String] group group permissions, can be passed as {Perm} object or String or Fixnum, see the method {PosixPerms.from} for details.
@param [String] world world permissions, can be passed as {Perm} object or String or Fixnum, see the method {PosixPerms.from} for details.
@param [String] sticky flag, can be passed as {Perm} object or String or Fixnum, see the method {PosixPerms.from} for details.
=end
    def initialize(user, group, world, sys = nil)
        @u = PosixPerms.from(user, 'user')
        @g = PosixPerms.from(group, 'group')
        @a = PosixPerms.from(world, 'world')
        @s = PosixPerms.from(sys, 'system')
    end

=begin rdoc
Standard Ruby object equality method for hashes and sets.
=end
    def eql?(other)
        self.u == other.u && self.g == other.g && self.a == other.a && self.s == other.s
    end
=begin rdoc
Redefine equality operator for simple comparison, not delegated to {#eql?}, code simply repeated here
for speed
=end
    def ==(other)
        self.u == other.u && self.g == other.g && self.a == other.a && self.s == other.s
    end

=begin
Converts to integer POSIX specification, 3 bits per each of User, Group, All aka World aka Others
=end
    def to_i; ('%d%d%d' % [@u, @g, @a]).to_i(8) end

end

Class Method Details

.from(source, kind) ⇒ Perm

Parses the DataMetaXtra::FileSys::Perm instance from the given source.

Parameters:

Returns:

  • (Perm)

    instance according to the description

Raises:

  • (ArgumentError)

    if the specs contain invalid character in case of a String or if the source is neither a String nor a DataMetaXtra::FileSys::Perm nor nil



205
206
207
208
209
210
211
212
213
214
# File 'lib/dataMetaXtra/fileSys.rb', line 205

def self.from(source, kind)
    case
        when source.kind_of?(NilClass) || source.kind_of?(Perm)
            source
        when source.kind_of?(String) || source.kind_of?(Fixnum)
            Perm.of(source)
        else
            raise ArgumentError, %<For #{kind} perms, invalid perm source: #{source.inspect} >
    end
end

Instance Method Details

#==(other) ⇒ Object

Redefine equality operator for simple comparison, not delegated to #eql?, code simply repeated here for speed



240
241
242
# File 'lib/dataMetaXtra/fileSys.rb', line 240

def ==(other)
    self.u == other.u && self.g == other.g && self.a == other.a && self.s == other.s
end

#eql?(other) ⇒ Boolean

Standard Ruby object equality method for hashes and sets.

Returns:

  • (Boolean)


233
234
235
# File 'lib/dataMetaXtra/fileSys.rb', line 233

def eql?(other)
    self.u == other.u && self.g == other.g && self.a == other.a && self.s == other.s
end

#to_iObject

Converts to integer POSIX specification, 3 bits per each of User, Group, All aka World aka Others



247
# File 'lib/dataMetaXtra/fileSys.rb', line 247

def to_i; ('%d%d%d' % [@u, @g, @a]).to_i(8) end