]> gitweb.michael.orlitzky.com - mailshears.git/blob - lib/rm/rm_plugin.rb
Document everything with YARD and fix some bugs along the way.
[mailshears.git] / lib / rm / rm_plugin.rb
1 require 'common/plugin.rb'
2
3 #
4 # Plugins for the removal of users and domains.
5 #
6 module RmPlugin
7
8 # Absorb the subclass run() magic from the Plugin::Run module.
9 extend Plugin::Run
10
11 # The runner class associated with removal plugins.
12 #
13 # @return [Class] the {RmRunner} class.
14 #
15 def self.runner()
16 return RmRunner
17 end
18
19
20 # The "dummy" runner class associated with removal plugins.
21 #
22 # @return [Class] the {RmDummyRunner} class.
23 #
24 def self.dummy_runner()
25 return RmDummyRunner
26 end
27
28
29 # Remove the *target* domain or user. This is a generic version of
30 # the {#remove_user} and {#remove_domain} operations that will
31 # dispatch based on the type of *target*.
32 #
33 # @param target [User,Domain] the user or domain to remove.
34 #
35 def remove(target)
36 # A generic version of remove_user/remove_domain that
37 # dispatches base on the class of the target.
38 if target.is_a?(User)
39 return remove_user(target)
40 elsif target.is_a?(Domain)
41 return remove_domain(target)
42 else
43 raise NotImplementedError
44 end
45 end
46
47
48 # Remove the given *domain*. Some plugins don't have a concept of
49 # domains, so the default implementation here removes all users that
50 # look like they belong to *domain*. Subclasses can be smarter.
51 #
52 # @param domain [Domain] the domain to remove.
53 #
54 def remove_domain(domain)
55 users = list_domains_users([domain])
56
57 # It's possible for a domain to exist with no users, but this
58 # default implementation is based on the assumption that it should
59 # work for plugins having no "domain" concept.
60 raise NonexistentDomainError.new(domain.to_s()) if users.empty?
61
62 users.each do |u|
63 remove_user(u)
64 end
65 end
66
67
68 # The interface for the "remove a user" operation. Subclasses
69 # need to implement this method so that it removes *user*.
70 #
71 # @param user [User] the user to remove.
72 #
73 def remove_user(user)
74 raise NotImplementedError
75 end
76
77 end