Skip to content

Instantly share code, notes, and snippets.

@pivotal-legacy
Created August 21, 2009 00:55
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save pivotal-legacy/171583 to your computer and use it in GitHub Desktop.
# config/plugins/plugins_to_test.yml
- user_auth
- social_pivots
# lib/plugin_dependency_limiter.rb
class Rails::Initializer
def load_plugins
# Only load the plugin under test
Rails::Plugin.new("vendor/plugins/#{ENV['PLUGIN']}").load(self)
end
def add_plugin_load_paths
# Do nothing. We'll handle plugin loading ourselves.
end
end
class Rails::Plugin
def self.plugins_of_interest
# Keep track of the Desert plugins we care about
@of_interest ||= YAML.load_file(RAILS_ROOT + "/config/plugins/plugins_to_test.yml").collect
end
def self.tracked_plugins
@tracked_plugins ||= []
end
def require_plugin_with_plugin_tracking(plugin_name)
self.class.tracked_plugins << plugin_name if self.class.plugins_of_interest.include?(plugin_name)
require_plugin_without_plugin_tracking(plugin_name)
end
alias_method_chain :require_plugin, :plugin_tracking
end
# config/routes.rb
ActionController::Routing::Routes.draw do |map|
if ENV['PLUGIN']
Rails::Plugin.tracked_plugins.each do |plugin|
map.routes_from_plugin(plugin)
end
map.routes_from_plugin(ENV['PLUGIN'])
end
end
# db/migration/001_migrate_desert_plugins.rb
class MigrateDesertPlugins < ActiveRecord::Migration
def self.up
Rails::Plugin.tracked_plugins.each do |plugin|
migrate_plugin(plugin, nil)
end
migrate_plugin(ENV['PLUGIN'], nil)
end
def self.down
raise ActiveRecord::IrreversibleMigration
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment