Permalink
Browse files

add option to ignore extensions where ruby's -= operator won't cut it.

…close #200
  • Loading branch information...
saturnflyer committed Apr 11, 2011
1 parent b1c2b69 commit 6f66516f2346e2739d93b5065a0ebbf2cee5d318
View
@@ -21,9 +21,9 @@
# By default, only English translations are loaded. Remove any of these from
# the list below if you'd like to provide any of the additional options
config.extensions -= [:dutch_language_pack, :french_language_pack, :german_language_pack,
:italian_language_pack, :japanese_language_pack, :russian_language_pack,
:debug]
config.ignore_extensions [:dutch_language_pack, :french_language_pack, :german_language_pack,
:italian_language_pack, :japanese_language_pack, :russian_language_pack,
:debug]
# Your secret key for verifying cookie session data integrity.
# If you change this key, all old sessions will become invalid!
@@ -21,9 +21,9 @@
# By default, only English translations are loaded. Remove any of these from
# the list below if you'd like to provide any of the additional options
config.extensions -= [:dutch_language_pack, :french_language_pack, :german_language_pack,
:italian_language_pack, :japanese_language_pack, :russian_language_pack,
:debug]
config.ignore_extensions [:dutch_language_pack, :french_language_pack, :german_language_pack,
:italian_language_pack, :japanese_language_pack, :russian_language_pack,
:debug]
# Your secret key for verifying cookie session data integrity.
# If you change this key, all old sessions will become invalid!
@@ -133,7 +133,7 @@ def load_extension_roots
[]
end
end
def select_extension_roots
all_roots = all_extension_roots.dup
roots = configuration.extensions.uniq.map do |ext_name|
@@ -151,6 +151,9 @@ def select_extension_roots
# replace the :all symbol with any remaining paths
roots[placeholder, 1] = all_roots
end
configuration.ignored_extensions.each do |removed|
roots.delete_if{|root| root.split('/').last.to_s == removed.to_s }
end
roots
end
@@ -33,7 +33,7 @@ def config # method must be defined before any initializers run
# Radiant::Config (aka Radiant.config) is the application-configuration model class
class Configuration < Rails::Configuration
attr_accessor :extension_paths
attr_accessor :extension_paths, :ignored_extensions
attr_writer :extensions
attr_accessor :view_paths
attr_accessor :extension_dependencies
@@ -64,6 +64,11 @@ def default_plugin_locators
def extensions
@extensions ||= all_available_extensions
end
def ignore_extensions(array)
self.ignored_extensions ||= []
self.ignored_extensions |= array
end
def all_available_extensions
# load vendorized extensions by inspecting load path(s)
@@ -31,20 +31,23 @@
it "should only load extensions specified in the configuration" do
@configuration.should_receive(:extensions).at_least(:once).and_return([:basic])
@configuration.should_receive(:ignored_extensions).at_least(:once).and_return([])
@instance.stub!(:all_extension_roots).and_return(@extension_paths)
@instance.send(:select_extension_roots).should == [File.expand_path("#{RADIANT_ROOT}/test/fixtures/extensions/basic")]
end
it "should load gem extensions with paths matching radiant-*-extension" do
gem_path = File.join RADIANT_ROOT, %w(test fixtures gems radiant-gem_ext-extension-61e0ad14a3ae)
@configuration.should_receive(:extensions).at_least(:once).and_return([:gem_ext])
@configuration.should_receive(:ignored_extensions).at_least(:once).and_return([])
@instance.stub!(:all_extension_roots).and_return([File.expand_path(gem_path)])
@instance.send(:select_extension_roots).should == [gem_path]
end
it "should load gem extensions packed by bundler from git" do
gem_path = File.join RADIANT_ROOT, %w(test fixtures gems radiant-gem_ext-extension-61e0ad14a3ae)
@configuration.should_receive(:extensions).at_least(:once).and_return([:gem_ext])
@configuration.should_receive(:ignored_extensions).at_least(:once).and_return([])
@instance.stub!(:all_extension_roots).and_return([File.expand_path(gem_path)])
@instance.send(:select_extension_roots).should == [gem_path]
end
@@ -54,6 +57,7 @@
extension_roots = extensions.map {|ext| File.expand_path("#{RADIANT_ROOT}/test/fixtures/extensions/#{ext}") }
@instance.stub!(:all_extension_roots).and_return(@extension_paths)
@configuration.should_receive(:extensions).at_least(:once).and_return(extensions)
@configuration.should_receive(:ignored_extensions).at_least(:once).and_return([])
@instance.send(:select_extension_roots).should == extension_roots
end
@@ -62,8 +66,21 @@
extension_roots = @extension_paths[0..-2].unshift(@extension_paths[-1])
@instance.stub!(:all_extension_roots).and_return(@extension_paths)
@configuration.should_receive(:extensions).at_least(:once).and_return(extensions)
@configuration.should_receive(:ignored_extensions).at_least(:once).and_return([])
@instance.send(:select_extension_roots).should == extension_roots
end
it "should not load any ignored extensions" do
extensions = [:load_order_red, :all, :load_order_green]
extensions -= [:basic]
extension_roots = @extension_paths[0..-2].unshift(@extension_paths[-1])
@instance.stub!(:all_extension_roots).and_return(@extension_paths)
@configuration.should_receive(:extensions).at_least(:once).and_return(extensions)
@configuration.should_receive(:ignored_extensions).at_least(:once).and_return([:basic])
roots = @instance.send(:select_extension_roots)
exts = roots.collect{|e| e.split('/').last }
exts.should_not include('basic')
end
it "should raise an error when an extension named in the configuration cannot be found" do
extensions = [:foobar]

0 comments on commit 6f66516

Please sign in to comment.