Skip to content

Commit

Permalink
Support radiant- prefix for gem extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh French committed Dec 23, 2009
1 parent 046670d commit aa03825
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/radiant/extension_loader.rb
Expand Up @@ -73,7 +73,7 @@ def load_extensions
@observer ||= DependenciesObserver.new(configuration).observe(::ActiveSupport::Dependencies)
self.extensions = load_extension_roots.map do |root|
begin
extension_file = "#{File.basename(root).sub(/^\d+_|-[\d.]+$/,'')}_extension"
extension_file = "#{File.basename(root).gsub(/^\d+_|^radiant-|-[\d.]+$/,'')}_extension"
extension = extension_file.camelize.constantize
extension.unloadable
extension.root = root
Expand Down Expand Up @@ -129,7 +129,7 @@ def select_extension_roots
:all
else
ext_path = all_roots.detect do |maybe_path|
File.basename(maybe_path).sub(/^\d+_|-[\d.]+$/, '') == ext_name.to_s
File.basename(maybe_path).gsub(/^\d+_|^radiant-|-[\d.]+$/, '') == ext_name.to_s
end
raise LoadError, "Cannot find the extension '#{ext_name}'!" if ext_path.nil?
all_roots.delete(ext_path)
Expand Down
2 changes: 1 addition & 1 deletion lib/radiant/initializer.rb
Expand Up @@ -44,7 +44,7 @@ def all_available_extensions
available.tap { |a| a << gem.specification.full_gem_path if gem.specification and Dir[gem.specification.full_gem_path + '/*_extension.rb' ].any? }
end
# strip version info to glean proper extension names
all.flatten.map {|f| File.basename(f).sub(/^\d+_|-[\d\.]+$/, '') }.sort.map {|e| e.to_sym }
all.flatten.map {|f| File.basename(f).gsub(/^\d+_|^radiant-|-[\d\.]+$/, '') }.sort.map {|e| e.to_sym }
end

def admin
Expand Down
7 changes: 7 additions & 0 deletions spec/lib/radiant/extension_loader_spec.rb
Expand Up @@ -42,6 +42,13 @@
@instance.send(:select_extension_roots).should == [gem_path]
end

it "should load gem extensions with a radiant- prefix" do
gem_path = File.join RADIANT_ROOT, %w(test fixtures gems radiant-gem_ext-0.0.0)
@configuration.should_receive(:extensions).at_least(:once).and_return([:gem_ext])
@instance.stub!(:all_extension_roots).and_return([File.expand_path gem_path])
@instance.send(:select_extension_roots).should == [gem_path]
end

it "should select extensions in an explicit order from the configuration" do
extensions = [:load_order_red, :load_order_blue, :load_order_green]
extension_roots = extensions.map {|ext| File.expand_path("#{RADIANT_ROOT}/test/fixtures/extensions/#{ext}") }
Expand Down
5 changes: 5 additions & 0 deletions spec/lib/radiant/initializer_spec.rb
Expand Up @@ -92,6 +92,11 @@
@configuration.gems = [Rails::GemDependency.new 'bogus_gem']
@configuration.all_available_extensions.should_not include(:bogus_gem)
end

it "should load gems with a radiant- prefix" do
@spec.stub!(:full_gem_path).and_return(File.join RADIANT_ROOT, %w(test fixtures gems radiant-gem_ext-0.0.0))
@configuration.all_available_extensions.should include(:gem_ext)
end
end
end

Expand Down
Empty file.

0 comments on commit aa03825

Please sign in to comment.