[Lipid-developers] instead of straight observers...

Jeremy Stell-Smith jeremystellsmith at gmail.com
Thu Jan 18 05:17:55 EST 2007


how about something more like this :

we'd have an extensions folder, and all the files in the extensions folder
would get auto loaded.  for example, email_notifier.rb would look something
like :

class Project
  plugin :email_notifier
end

class EmailNotifier
  attr_accessor :emails

  def initialize
    @emails = []
  end

  def build_finished(build)
    return if @emails.empty?

    if build.failed?
      ...
    end
  end

  def memento
    return nil if emails.empty?

    "  project.email_notifier.emails = [\n" +
    @emails.map{ |email| '      ' + email.to_s.strip.inspect }.join(",\n") +
"\n" +
    "  ]"
  end
end



so basically, in each extension file we would :
1) add our extension class as a "plugin" to project, that is something that
could be referred to directly and is ALWAYS instantiated (though it may be
disabled for most extensions unless explicitly enabled in the config
file)  the purpose of this is that it's a lot easier to configure something
that already exists both from the config file and the web app as well

2) our extension class relies on public methods having special names
(convention over configuration).  the "plugin" method would also register
our extension with the project.  for every "event" like build_started,
build_finished, checking_for_modifications, etc, it would see if any
extension "responds_to?" the event.  if so, it will call its method.

3) memento will be required for all plugins so we can persist - however save
as little as possible - in some cases, this will be nothing

4) additionally, if this plugin is configurable from the web, we should put
calls in here to extend the controller / views to support it, but that's for
later, I'm totally cool hardcoding for now.

I'm going to sleep but I wanted to get feedback and see if I could change
our direction a bit w/o actually implementing it.

Good work on the refactorings, Alex,

Jeremy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/lipid-developers/attachments/20070118/28cd29f7/attachment.html 


More information about the Lipid-developers mailing list