Document everything with YARD and fix some bugs along the way.
[mailshears.git] / lib / mv / mv_dummy_runner.rb
1 require 'common/runner'
2
3 # Dummy implementation of a {MvRunner}. Its <tt>run()</tt> method will
4 # tell you what would have been moved, but will not actually perform
5 # the operation.
6 #
7 class MvDummyRunner
8 include Runner
9
10 # Pretend to move *src* to *dst* with *plugin*. Some "what if"
11 # information will be output to stdout. This is useful to see if
12 # there would be (for example) a username collision at *dst* before
13 # attempting the move in earnest.
14 #
15 # @param cfg [Configuration] the configuration options to pass to
16 # the *plugin* we're runnning.
17 #
18 # @param plugin [Class] plugin class that will perform the move.
19 #
20 # @param src [User] the source user to be moved.
21 #
22 # @param dst [User] the destination user, to which we will move *src*.
23 #
24 def run(cfg, plugin, src, dst)
25
26 if src.is_a?(Domain) or dst.is_a?(Domain) then
27 msg = 'only users can be moved'
28 raise NotImplementedError.new(msg)
29 end
30
31 # Since we're not actually moving anything, the destination
32 # description is really only useful for seeing whether or not we'd
33 # be trying to move in on top of an existing account.
34 src_description = plugin.describe(src)
35 dst_description = plugin.describe(dst)
36
37 msg = "Would move user #{src} "
38
39 # Only append the extra description if it's useful.
40 if not src_description.nil? and
41 not src_description.empty? and
42 not src_description == src.to_s() then
43 msg += "(#{src_description}) "
44 end
45
46 msg += "to #{dst}"
47
48 # Only append the extra description if it's useful.
49 if not dst_description.nil? and
50 not dst_description.empty? and
51 not dst_description == dst.to_s() then
52 msg += " (#{dst_description})"
53 end
54
55 msg += "."
56 report(plugin, msg)
57 end
58
59 end