On 31/01/2008, Sven Fuchs <[EMAIL PROTECTED]> wrote:
> like I mentioned a while back Rick asked me regarding Engines as a
> basis for Mephisto plugins.

It's great news that Rick has found the engines plugin useful.

> 1. About info: we've omitted about.yml from Engines for Rails 2.0
> recently and you already mentioned that this could possibly be
> restored. On the one hand Rick said that he doesn't really care about
> this, but on the other hand people actually seem to use this
> information (e.g. the plugin authors website is displayed in the
> Mephisto admin interface and people use this link to lookup
> information about the plugin).

Adding the about.yml information is something we can definitely
re-include. Originally, we would simply load about.yml into a Hash
which can be accessed from the plugin instance:

about.yml
---
:author: James
:url: http://interblah.net
:version: 2.0.1
:description: Blah blah

becomes

plugin = Engines.plugins[:my_plugin]
plugin.about
# ==> { :version => "2.0.1", :author => "James", :url =>
"http://interblah.net"; ... }

This is relatively easy to support - in fact, is there any reason why
this couldn't be implemented as a patch to Rails core itself?
Regardless, my only suggestion would be that the plugins mechanism is
not particular about the specific keys in about.yml - anything can be
present. If Mephisto expects a particular set of keys to be present,
that should be enforced in the application itself.

> 2. Configuration info: Mephisto provides means to configure a plugin
> through an option directive. E.g. in a feedback form plugin there
> might be an option to configure the confirmation message that's
> displayed when the feedback for has been submitted (bad example but
> you get the idea). The option and its default value is defined in the
> plugin, it's current value is pulled from the database if a record is
> present (otherwise the default value is used). Mephisto could switch
> from using ActiveRecord as a storage for plugin configuration data to
> something else, e.g. another YAML file, Ruby code or whatever.
>
> A possible solution for both requirements that I personally like could
> be:
>
> With Rails 2.0 plugins we can do all the about and configuration stuff
> from within init.rb because this file is evaluated within the plugin's
> scope. Because init.rb is overwritten when the plugin get's
> reinstalled (so the config customization would get lost) we could look
> for a (e.g.) config.rb file and evaluate it alongside with the plugin
> init.rb file if it's present. This config.rb file would allow to
> define something like:
>
> author 'James'
> version '1.0'
> website 'http://...'
>
> option :feedback_confirm_msg, 'Thanks!'
> option :foo, 'bar'
>
> What do you think?
>

So the config.rb would be stored somewhere outside of /vendor/plugins?
I'm not sure this is a particularly good fit for the engines plugin
itself - it seems better that Mephisto makes some class available to
its plugins to support this. Something like

  create_table :plugin_configs do |t|
    t.string :plugin
    t.string :key
    t.string :value
  end

So in a table we have tuples of plugin name, key and value. Next lets
set up a base class that can access this table

mephisto/lib/plugin_config.rb:
  class PluginConfig < ActiveRecord::Base

    # this lets us set and store default values in subclasses of PluginConfig
    class_inheritable_hash :defaults
    def self.default(key, value)
      defaults[key.to_s] = value
    end

    # Try and load a stored config tuple - otherwise, return any stored default
    def self.config[](key)
      stored_value(key) || defaults[key.to_s]
    end

    # Create or overwrite any existing tuple for this plugin
    def self.config[]=(key, value)
      config = stored_config(key)
      if config
        config.update_attribute(:value, value)
      else
        create(:plugin => self.name, :key => key, :value => value)
      end
    end

    def self.stored_value(key)
      stored_config = find_by_key_and_plugin(key, self.name)
      stored_config ? stored_config.value : nil
    end

    # I imagine Mephisto itself will want to load all of the stored
config tuples
    # for a particular plugin
    def all_stored_configuration_options
      find_all_by_plugin(self.name)
    end

    # Returns all configuration options declared by the subclass, including any
    # defaults. Probably useful in the Mephisto admin interface too.
    def all_configuration_options
      stored_configs = all_stored_configuration_options
      stored_configs_and_defaults = defaults.dup
      stored_configs.each do |config|
        stored_configs_and_defaults[config.key] = config.value
      end
      stored_configs_and_defaults
    end
  end


vendor/plugins/my_plugin/init.rb

  class MyPlugin < PluginConfig
    default :admin_email, "[EMAIL PROTECTED]"
  end

vendor/plugins/my_plugin/lib/some_thing.rb

  class SomeThing
    # ...
    def send_email(body)
      send_email_to(MyPlugin.config[:admin_email], body)
    end
    # ...
  end


.... anyway. That's just off the top of my head, but the point is that
I'm not sure that it's anything that the engines plugin should really
handle explicitly. Any thoughts?

-- 
* J *
  ~
_______________________________________________
Engine-Developers mailing list
[email protected]
http://lists.rails-engines.org/listinfo.cgi/engine-developers-rails-engines.org

Reply via email to