Document everything with YARD and fix some bugs along the way.
[mailshears.git] / lib / rm / rm_runner.rb
1 require 'common/errors'
2 require 'common/runner'
3
4 # Perform the removal of users/domains using {RmPlugin}s.
5 #
6 class RmRunner
7 include Runner
8
9 # Run *plugin* to remove the users/domains in *targets*. The method
10 # signature includes the unused *cfg* for consistency with the
11 # runners that do need a {Configuration}.
12 #
13 # @param cfg [Configuration] unused.
14 #
15 # @param plugin [Class] plugin class that will perform the removal.
16 #
17 # @param targets [Array<User,Domain>] the users and domains to be
18 # removed.
19 #
20 def run(cfg, plugin, *targets)
21 targets.each do |target|
22 remove_target(plugin, target)
23 end
24 end
25
26
27 protected;
28
29 # Remove *target* using *plugin*. This operation is separate from
30 # the <tt>run()</tt> method so that it can be accessed by the prune
31 # runner.
32 #
33 # @param plugin [RmPlugin] the plugin that will remove the *target*.
34 #
35 # @param target [User,Domain] the user or domain to remove.
36 #
37 def remove_target(plugin, target)
38 target_description = plugin.describe(target)
39
40 begin
41 plugin.remove(target)
42 msg = "Removed #{target.class.to_s().downcase()} #{target}"
43
44 # Only append the extra description if it's useful.
45 if not target_description.nil? and
46 not target_description.empty? and
47 not target_description == target.to_s() then
48 msg += " (#{target_description})"
49 end
50 msg += '.'
51
52 report(plugin, msg)
53 rescue NonexistentDomainError, NonexistentUserError => e
54 report(plugin, "#{target.class.to_s()} #{e.to_s} not found.")
55 end
56 end
57 end