]> gitweb.michael.orlitzky.com - mailshears.git/blob - lib/common/runner.rb
Fix warnings with newer minitest versions.
[mailshears.git] / lib / common / runner.rb
1 # Methods inherited by the various runner classes ({PruneRunner},
2 # {MvRunner}, {RmRunner}).
3 #
4 module Runner
5
6
7 # The main thing a runner does is <tt>run()</tt>. Each runner will
8 # actually take a different number of arguments, so their
9 # <tt>run()</tt> signatures will differ. This stub is only here to
10 # let you know that it needs to be implemented.
11 #
12 # @param args [Array<Object>] whatever arguments the real implementation
13 # would take.
14 #
15 def run(*args)
16 raise NotImplementedError
17 end
18
19
20 # When we're describing a user or domain, we often want to output
21 # some additional description of it. But then, sometimes that
22 # additional description is pointless, like when it's exactly the
23 # same as the username that we're already outputting. This function
24 # determines whether or not *desc* is pointless for *target*.
25 #
26 # @param target [User,Domain] the user or domain described by *desc*.
27 #
28 # @param desc [String] a string description of *target*.
29 #
30 # @return [Boolean] true if *desc* is a pointless description of
31 # *target* and false otherwise.
32 #
33 def pointless?(target, desc)
34 return (desc.nil? or desc.empty? or desc == target.to_s())
35 end
36
37
38 # If *desc* is not a pointless description of *target*, return the
39 # string representation of *target* followed by *desc* in
40 # parentheses. If *desc* is pointless, we return only the string
41 # representation of *target*
42 #
43 # @param target [User,Domain] the user or domain we want to describe
44 # as a string.
45 #
46 # @param desc [String] a string description of *target*.
47 #
48 # @return [String] the string representation of *target*, possibly
49 # followed by the non-pointless description *desc*.
50 #
51 def add_description(target, desc)
52 if pointless?(target, desc)
53 return target.to_s()
54 else
55 return target.to_s() + " (#{desc})"
56 end
57 end
58
59
60 # Report a message from the given *plugin*. All this does is prefix
61 # the message with the plugin name and then print it to stdout.
62 #
63 # @param plugin [Object] t plugin object that generated the message
64 # we're reporting.
65 #
66 # @param msg [String] the message to report.
67 #
68 def report(plugin, msg)
69 print "#{plugin.class.to_s()} - "
70 puts msg
71 end
72
73 end