Class: DataMetaXtra::FileSys::IdName

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

Overview

Generic Id and Name pair, good for any such situation, but in this case used specifically for POSIX user/group ID+Name.

Regarding equality of these instances, it’s better to use one of the components straight, although the both the #eql? and == method override are provided.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, name) ⇒ IdName

Convenience constructor

Raises:

  • (ArgumentError)

    if the name string is empty or contains invalid characters



281
282
283
284
# File 'lib/dataMetaXtra/fileSys.rb', line 281

def initialize(id, name)
    raise ArgumentError, %<Invalid POSIX name: "#{name}"> unless name =~ /^[a-z][\w\.-]*$/
    @id, @name = id, name
end

Instance Attribute Details

#idFixnum

Returns numeric ID associated with the name.

Returns:

  • (Fixnum)

    numeric ID associated with the name.



264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
# File 'lib/dataMetaXtra/fileSys.rb', line 264

class IdName
    attr_accessor :id, :name

Name-only instance, id set to nil. Useful for cases when ID is irrelevant, such as transferring directory structure
between hosts.
@raise [ArgumentError] if the name string is empty or contains invalid characters
@param [String] name the {#name}

    def self.forName(name)
        IdName.new(nil, name)
    end

Convenience constructor
@raise [ArgumentError] if the name string is empty or contains invalid characters

    def initialize(id, name)
        raise ArgumentError, %<Invalid POSIX name: "#{name}"> unless name =~ /^[a-z][\w\.-]*$/
        @id, @name = id, name
    end

Standard Ruby object equality method for hashes and sets.

    def eql?(other)
        self.id == other.id && self.name == other.name
    end
Redefine equality operator for simple comparison, not delegated to {#eql?}, code simply repeated here
for speed

    def ==(other)
        self.id == other.id && self.name == other.name
    end
end

#nameString

Returns the name associated with the ID.

Returns:

  • (String)

    the name associated with the ID



264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
# File 'lib/dataMetaXtra/fileSys.rb', line 264

class IdName
    attr_accessor :id, :name

Name-only instance, id set to nil. Useful for cases when ID is irrelevant, such as transferring directory structure
between hosts.
@raise [ArgumentError] if the name string is empty or contains invalid characters
@param [String] name the {#name}

    def self.forName(name)
        IdName.new(nil, name)
    end

Convenience constructor
@raise [ArgumentError] if the name string is empty or contains invalid characters

    def initialize(id, name)
        raise ArgumentError, %<Invalid POSIX name: "#{name}"> unless name =~ /^[a-z][\w\.-]*$/
        @id, @name = id, name
    end

Standard Ruby object equality method for hashes and sets.

    def eql?(other)
        self.id == other.id && self.name == other.name
    end
Redefine equality operator for simple comparison, not delegated to {#eql?}, code simply repeated here
for speed

    def ==(other)
        self.id == other.id && self.name == other.name
    end
end

Class Method Details

.forName(name) ⇒ Object

Name-only instance, id set to nil. Useful for cases when ID is irrelevant, such as transferring directory structure between hosts.

Parameters:

  • name (String)

    the #name

Raises:

  • (ArgumentError)

    if the name string is empty or contains invalid characters



273
274
275
# File 'lib/dataMetaXtra/fileSys.rb', line 273

def self.forName(name)
    IdName.new(nil, name)
end

Instance Method Details

#==(other) ⇒ Object

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



296
297
298
# File 'lib/dataMetaXtra/fileSys.rb', line 296

def ==(other)
    self.id == other.id && self.name == other.name
end

#eql?(other) ⇒ Boolean

Standard Ruby object equality method for hashes and sets.

Returns:

  • (Boolean)


289
290
291
# File 'lib/dataMetaXtra/fileSys.rb', line 289

def eql?(other)
    self.id == other.id && self.name == other.name
end