views:

13

answers:

1

I can't seem to find any documentation on how to do the following: I need to provide a config variable for any applications using my engine so that they can easily pass settings to my engine.

Does anyone have any links to a proper or accepted way to do this?

EDIT: As an update, I figured out a decent way to do this. Code is below.

# file: lib/my_engine.rb
module MyEngine

  class Engine < Rails::Engine

    initializer "my_engine.configure_rails_initialization" do |app|
      # Engine configures Rails app here, this is not what my question was about
    end

  end

  # This is what I was trying to figure out
  def self.config(&block)
    @@config ||= MyEngine::Configuration.new

    yield @@config if block

    return @@config
  end

end

This allows any application using my engine to configure it like below in any of their initializers or their environment.rb file, calling any methods defined in the MyEngine::Configuration class:

MyEngine.config do |config|
  config.some_configuration_option = "Whatever"
end