/
list.rb
87 lines (79 loc) · 2.76 KB
/
list.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# encoding: utf-8
# Copyright (c) [2018] SUSE LLC
#
# All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of version 2 of the GNU General Public License as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, contact SUSE LLC.
#
# To contact SUSE LLC about this file by physical or electronic mail, you may
# find current contact information at www.suse.com.
require "forwardable"
module Y2Autoinstallation
module AutoinstIssues
# List of general AutoYaST problems
#
# @example Registering some problems
# list = List.new
# list.add(:invalid_value, "firewall", "interfaces",
# "eth0",
# _("This interface has been defined for more than one zone."))
#
# @example Iterating through the list of problems
# list.map(&:severity) #=> [:warn]
class List
include Yast::Logger
include Enumerable
extend Forwardable
def_delegators :@items, :each, :empty?, :<<
# Constructor
def initialize
@items = []
end
# Add a problem to the list
#
# The type of the problem is identified as a symbol which name is the
# underscore version of the class which implements it. For instance,
# `InvalidValue` would be referred as `:invalid_value`.
#
# If a given type of problem requires some additional arguments, they
# should be added when calling this method. See the next example.
#
# @example Adding a problem with additional arguments
# list = List.new
# list.add(:invalid_value, "firewall", "FW_DEV_INT", "1",
# _("Is not supported anymore."))
# list.empty? #=> false
#
# @param type [Symbol] Issue type
# @param extra_args [Array] Additional arguments for the given problem
# @return [Array<Issue>] List of problems
def add(type, *extra_args)
class_name = type.to_s.split("_").map(&:capitalize).join
klass = Y2Autoinstallation::AutoinstIssues.const_get(class_name)
self << klass.new(*extra_args)
end
# Determine whether any of the problem on the list is fatal
#
# @return [Boolean] true if any of them is a fatal problem
def fatal?
any?(&:fatal?)
end
# Returns an array containing registered problems
#
# @return [Array<Issue>] List of problems
def to_a
@items
end
end
end
end