Class: Y2Issues::Location

Inherits:
Object
  • Object
show all
Defined in:
library/general/src/lib/y2issues/location.rb

Overview

Represent the location of an error

It can be a file, a section of an AutoYaST profile, etc. This class is rather open and its API might change once we know more about error reporting.

The concept of "location" is introduce to tell the user where to look for a problem and as a mechanism to group the issues.

A location is composed by three parts:

  • type: whether the location is a file, an AutoYaST profile section, etc.
  • path: location path (file path, AutoYaST profile path, etc.)
  • id: it can be the file line, a key, an AutoYaST element name, etc. This element is optional.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, path, id = nil) ⇒ Location

Returns a new instance of Location.

Parameters:

  • type (String)

    Location type

  • path (String)

    Location path

  • id (String, nil) (defaults to: nil)

    Location ID, if needed



69
70
71
72
73
# File 'library/general/src/lib/y2issues/location.rb', line 69

def initialize(type, path, id = nil)
  @type = type
  @path = path
  @id = id
end

Instance Attribute Details

#idString? (readonly)

Returns Location ID within the path.

Returns:

  • (String, nil)

    Location ID within the path



40
41
42
# File 'library/general/src/lib/y2issues/location.rb', line 40

def id
  @id
end

#pathString (readonly)

Returns Location path (a file path, an AutoYaST section path, and so on).

Returns:

  • (String)

    Location path (a file path, an AutoYaST section path, and so on)



38
39
40
# File 'library/general/src/lib/y2issues/location.rb', line 38

def path
  @path
end

#typeString (readonly)

Returns Location type ("file", "autoyast", etc.).

Returns:

  • (String)

    Location type ("file", "autoyast", etc.)



36
37
38
# File 'library/general/src/lib/y2issues/location.rb', line 36

def type
  @type
end

Class Method Details

.parse(str) ⇒ Location

Parse a string and creates a location

The string contains the type, the path and the id, separated by colons.

Examples:

AutoYaST section reference

location = Location.parse("autoyast:partitioning,1,partition,0:filesystem_type")
location.type #=> "ay"
location.path #=> "partitioning,1,partition,0"
location.id   #=> "filesystem_type"

File reference

location = Location.parse("file:/etc/sysconfig/network/ifcfg-eth0:BOOTPROTO")
location.type #=> "file"
location.path #=> "/etc/sysconfig/network/ifcfg-eth0"
location.id   #=> "BOOTPROTO"

Parameters:

  • str (String)

    String representing the path

Returns:

See Also:



61
62
63
64
# File 'library/general/src/lib/y2issues/location.rb', line 61

def self.parse(str)
  type, path, id = str.split(":")
  new(type, path, id)
end

Instance Method Details

#==(other) ⇒ Boolean Also known as: eql?

Determines whether two locations are the same

Parameters:

Returns:

  • (Boolean)


87
88
89
# File 'library/general/src/lib/y2issues/location.rb', line 87

def ==(other)
  type == other.type && path == other.path && id == other.id
end

#to_sString

Returns a string-based representation of the location

Returns:

  • (String)

    String-based representation

See Also:



79
80
81
# File 'library/general/src/lib/y2issues/location.rb', line 79

def to_s
  [type, path, id].compact.join(":")
end