public
Last active

  • Download Gist
testing_desert_plugins.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
# 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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.