@@ -40,6 +40,21 @@ def add_error(msg = nil, &block)
40
40
add_alert ( :error , msg , &block )
41
41
end
42
42
43
+ # Add an info message that will be provided to the user as early possible when using
44
+ # this instance of a module, either when they select it with the `use`
45
+ # command, when the module is about to start running, or when the module
46
+ # generates its output.
47
+ #
48
+ # @param msg [String] an optional info message
49
+ # @param block [Proc] an optional block that will be executed in the
50
+ # context of the module instance at alert time to generate the
51
+ # message. If provided the msg parameter is ignored.
52
+ # @return [true, nil] whether or not the message was added to the list of
53
+ # info messages
54
+ def add_info ( msg = nil , &block )
55
+ add_alert ( :info , msg , &block )
56
+ end
57
+
43
58
# @return [Array<String, Proc>] a list of warning message strings, or
44
59
# blocks (see #get_alerts)
45
60
def warnings
@@ -52,6 +67,12 @@ def errors
52
67
get_alerts ( :error )
53
68
end
54
69
70
+ # @return [Array<String, Proc>] a list of info message strings, or
71
+ # blocks (see #get_alerts)
72
+ def infos
73
+ get_alerts ( :info )
74
+ end
75
+
55
76
# @param level [Symbol] The alert level to return
56
77
# @return [Array<String, Proc>] A list of `level` alerts, either in string
57
78
# or block form. Blocks expect to be executed in the context of a fully
@@ -135,6 +156,21 @@ def add_error(msg = nil, &block)
135
156
add_alert ( :error , msg , &block )
136
157
end
137
158
159
+ # Add an info message that will be provided to the user as early possible when using
160
+ # this instance of a module, either when they select it with the `use`
161
+ # command, when the module is about to start running, or when the module
162
+ # generates its output.
163
+ #
164
+ # @param msg [String] an optional info message
165
+ # @param block [Proc] an optional block that will be executed in the
166
+ # context of the module instance at alert time to generate the
167
+ # message. If provided the msg parameter is ignored.
168
+ # @return [true, nil] whether or not the message was added to the list of
169
+ # info messages
170
+ def add_info ( msg = nil , &block )
171
+ add_alert ( :info , msg , &block )
172
+ end
173
+
138
174
# This method allows modules to tell the framework if they are usable
139
175
# on the system that they are being loaded on in a generic fashion.
140
176
# By default, all modules are indicated as being usable. An example of
@@ -160,6 +196,11 @@ def errors
160
196
get_alerts ( :error )
161
197
end
162
198
199
+ # @return [Array<String>] a list of info strings to show the user
200
+ def infos
201
+ get_alerts ( :info )
202
+ end
203
+
163
204
# Similar to {ClassMethods#get_alerts}, but executes each registered block in
164
205
# the context of this module instance and returns a flattened list of strings.
165
206
# (see {ClassMethods#get_alerts})
@@ -215,5 +256,12 @@ def alert_user
215
256
self . you_have_been_warned [ msg . hash ] = true
216
257
end
217
258
end
259
+
260
+ infos . each do |msg |
261
+ if msg && !self . you_have_been_warned [ msg . hash ]
262
+ print_line ( msg )
263
+ self . you_have_been_warned [ msg . hash ] = true
264
+ end
265
+ end
218
266
end
219
267
end
0 commit comments