]>
gitweb.michael.orlitzky.com - mailshears.git/blob - plugin.rb
c6f750bc3f4d4c2f20e1c11c31f372e849afd711
1 require 'common/domain'
4 # All plugins should include this module. It defines the basic
5 # operations that all plugins are supposed to support.
9 # Module methods, meant to be extended. Includers can explicitly
10 # extend this to get a run() method defined in terms of their own
11 # runner() and dummy_runner() methods.
14 # Callback, called whenever another class or module includes this
15 # one. The parameter given is the name of the class or module
27 # The Runner associated with this plugin.
28 raise NotImplementedError
32 # The DummyRunner associated with this plugin.
33 raise NotImplementedError
37 includers().each
do |includer
|
38 plugin
= includer
.new(cfg
)
40 if cfg
.i_mean_business
then
41 runner
= runner().new()
43 runner
= dummy_runner().new()
46 # The splat passes the correct (we hope) number of arguments to the
47 # appropriate runner. The Rm(Dummy)Runner have splats on their
48 # *target arguments as well, to turn ARGV back into an array.
49 runner
.run(plugin
, *args
)
55 # A generic version of describe_user/describe_domain that
56 # dispatches base on the class of the target.
58 return describe_user(target
)
59 elsif target
.is_a
?(Domain
)
60 return describe_domain(target
)
62 raise NotImplementedError
66 def describe_domain(domain
)
67 # Provide a "description" of the domain. This is output along
68 # with the domain name and can be anything of use to the system
70 raise NotImplementedError
73 def describe_user(user
)
74 # Provide a "description" of the user. This is output along
75 # with the domain name and can be anything of use to the system
77 raise NotImplementedError
81 # Return a list of all users managed by this plugin.
82 raise NotImplementedError
86 # Does the given username exist for this plugin? We use a naive
87 # implementation here based on list_users() which is required to
88 # exist above. Plugins can override this with something fast.
90 return users
.include?(user
)
93 def list_domains_users(domains
)
94 # Get all users belonging to the given domains. If a user has
95 # domainpart "example.com" then it belongs to the domain
98 # This uses a naive loop, but relies only on the existence of a
99 # list_users() method which is guaranteed above. More efficient
100 # implementations can usually be made within the plugin.
103 users
= list_users();
105 matches
= users
.select
do |user
|
106 user
.domainpart() == d
.to_s()
109 domains_users +
= matches