]>
gitweb.michael.orlitzky.com - mailshears.git/blob - 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
24 # The Runner associated with this plugin.
25 raise NotImplementedError
29 # The RummyRunner associated with this plugin.
30 raise NotImplementedError
34 includers().each
do |includer
|
35 plugin
= includer
.new(cfg
)
37 if cfg
.i_mean_business
then
38 runner
= runner().new()
40 runner
= dummy_runner().new()
43 # The splat passes the correct (we hope) number of arguments to the
44 # appropriate runner. The Rm(Dummy)Runner have splats on their
45 # *target arguments as well, to turn ARGV back into an array.
46 runner
.run(plugin
, *args
)
51 def describe_domain(domain
)
52 # Provide a "description" of the domain. This is output along
53 # with the domain name and can be anything of use to the system
55 raise NotImplementedError
58 def describe_user(user
)
59 # Provide a "description" of the user. This is output along
60 # with the domain name and can be anything of use to the system
62 raise NotImplementedError
66 # Return a list of all users managed by this plugin.
67 raise NotImplementedError
70 def user_exists(username
)
71 # Does the given username exist for this plugin? We use a naive
72 # implementation here based on list_users() which is required to
73 # exist above. Plugins can override this with something fast.
75 return users
.include?(username
)
78 def list_domains_users(domains
)
79 # Get all usernames belonging to the given domains. If a username
80 # ends in @example.com, it belongs to the domain example.com
82 # This uses a naive loop, but relies only on the existence of a
83 # list_users() method which is guaranteed above. More efficient
84 # implementations can usually be made within the plugin.
87 usernames
= list_users();
89 matches
= usernames
.select
do |username
|
93 domains_users +
= matches