]> gitweb.michael.orlitzky.com - mailshears.git/blob - lib/rm/rm_runner.rb
Take a stab in the dark at AgenDAV v2.1.0 support.
[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()} "
43 msg += add_description(target, target_description)
44 msg += '.'
45
46 report(plugin, msg)
47 rescue NonexistentDomainError, NonexistentUserError => e
48 report(plugin, "#{target.class.to_s()} #{e.to_s} not found.")
49 end
50 end
51 end