]>
gitweb.michael.orlitzky.com - mailshears.git/blob - lib/common/plugin.rb
1 # All plugins should include this module. It defines the basic
2 # operations that all plugins are supposed to support.
6 # Module methods, meant to be extended. Includers can explicitly
7 # extend this to get a run() method defined in terms of their own
8 # runner() and dummy_runner() methods.
11 # Callback, called whenever another class or module includes this
12 # one. The parameter given is the name of the class or module
23 # The Runner associated with this plugin.
24 raise NotImplementedError
28 # The RummyRunner associated with this plugin.
29 raise NotImplementedError
33 includers().each
do |includer
|
34 plugin
= includer
.new(cfg
)
36 if cfg
.i_mean_business
then
37 runner
= runner().new()
39 runner
= dummy_runner().new()
42 # The splat passes the correct (we hope) number of arguments to the
43 # appropriate runner. The Rm(Dummy)Runner have splats on their
44 # *target arguments as well, to turn ARGV back into an array.
45 runner
.run(plugin
, *args
)
50 def describe_domain(domain
)
51 # Provide a "description" of the domain. This is output along
52 # with the domain name and can be anything of use to the system
54 raise NotImplementedError
57 def describe_user(user
)
58 # Provide a "description" of the user. This is output along
59 # with the domain name and can be anything of use to the system
61 raise NotImplementedError
65 # Return a list of all users managed by this plugin.
66 raise NotImplementedError
69 def user_exists(username
)
70 # Does the given username exist for this plugin? We use a naive
71 # implementation here based on list_users() which is required to
72 # exist above. Plugins can override this with something fast.
74 return users
.include?(username
)
77 def list_domains_users(domains
)
78 # Get all usernames belonging to the given domains. If a username
79 # ends in @example.com, it belongs to the domain example.com
81 # This uses a naive loop, but relies only on the existence of a
82 # list_users() method which is guaranteed above. More efficient
83 # implementations can usually be made within the plugin.
86 usernames
= list_users();
88 matches
= usernames
.select
do |username
|
92 domains_users +
= matches