X-Git-Url: http://gitweb.michael.orlitzky.com/?p=mailshears.git;a=blobdiff_plain;f=lib%2Fmv%2Fmv_dummy_runner.rb;h=9ed655a4719ad30785b9a917624bc3dadfd7c768;hp=11f2ff5c7cf94befb458b6f99433df4f7a056938;hb=df4e02ebf6a4e28a58abcb298a4442a245ad0b15;hpb=8610295a5340a82a6c95f68fe983fe0ce5a2e382 diff --git a/lib/mv/mv_dummy_runner.rb b/lib/mv/mv_dummy_runner.rb index 11f2ff5..9ed655a 100644 --- a/lib/mv/mv_dummy_runner.rb +++ b/lib/mv/mv_dummy_runner.rb @@ -1,14 +1,59 @@ require 'common/runner' +# Dummy implementation of a {MvRunner}. Its run() method will +# tell you what would have been moved, but will not actually perform +# the operation. +# class MvDummyRunner include Runner - def run(plugin, src, dst) - if src.include?('@') then - puts "Would move user: #{src} to #{dst}" - else - raise NotImplementedError.new('Only users can be moved.') + # Pretend to move *src* to *dst* with *plugin*. Some "what if" + # information will be output to stdout. This is useful to see if + # there would be (for example) a username collision at *dst* before + # attempting the move in earnest. + # + # @param cfg [Configuration] the configuration options to pass to + # the *plugin* we're runnning. + # + # @param plugin [Class] plugin class that will perform the move. + # + # @param src [User] the source user to be moved. + # + # @param dst [User] the destination user, to which we will move *src*. + # + def run(cfg, plugin, src, dst) + + if src.is_a?(Domain) or dst.is_a?(Domain) then + msg = 'only users can be moved' + raise NotImplementedError.new(msg) + end + + # Since we're not actually moving anything, the destination + # description is really only useful for seeing whether or not we'd + # be trying to move in on top of an existing account. + src_description = plugin.describe(src) + dst_description = plugin.describe(dst) + + msg = "Would move user #{src} " + + # Only append the extra description if it's useful. + if not src_description.nil? and + not src_description.empty? and + not src_description == src.to_s() then + msg += "(#{src_description}) " end + + msg += "to #{dst}" + + # Only append the extra description if it's useful. + if not dst_description.nil? and + not dst_description.empty? and + not dst_description == dst.to_s() then + msg += " (#{dst_description})" + end + + msg += "." + report(plugin, msg) end end