mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Rails::Engine.find(path) - method to find engine by path
This commit is contained in:
parent
5df72a238e
commit
051127d4d3
4 changed files with 34 additions and 8 deletions
|
@ -8,14 +8,6 @@ module Rails
|
|||
@all.each(&block) if block
|
||||
@all
|
||||
end
|
||||
|
||||
def railties
|
||||
@railties ||= ::Rails::Railtie.subclasses.map(&:instance)
|
||||
end
|
||||
|
||||
def engines
|
||||
@engines ||= ::Rails::Engine.subclasses.map(&:instance)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -371,6 +371,11 @@ module Rails
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Finds engine with given path
|
||||
def find(path)
|
||||
Rails::Engine::Railties.engines.find { |r| File.expand_path(r.root.to_s) == File.expand_path(path.to_s) }
|
||||
end
|
||||
end
|
||||
|
||||
delegate :middleware, :root, :paths, :to => :config
|
||||
|
|
|
@ -18,6 +18,16 @@ module Rails
|
|||
Plugin.all(plugin_names, @config.paths["vendor/plugins"].existent)
|
||||
end
|
||||
end
|
||||
|
||||
def self.railties
|
||||
@railties ||= ::Rails::Railtie.subclasses.map(&:instance)
|
||||
end
|
||||
|
||||
def self.engines
|
||||
@engines ||= ::Rails::Engine.subclasses.map(&:instance)
|
||||
end
|
||||
|
||||
delegate :railties, :engines, :to => "self.class"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -702,5 +702,24 @@ module RailtiesTest
|
|||
|
||||
assert_equal "foo", Bukkits.table_name_prefix
|
||||
end
|
||||
|
||||
test "fetching engine by path" do
|
||||
@plugin.write "lib/bukkits.rb", <<-RUBY
|
||||
module Bukkits
|
||||
class Engine < ::Rails::Engine
|
||||
end
|
||||
end
|
||||
RUBY
|
||||
|
||||
boot_rails
|
||||
require "#{rails_root}/config/environment"
|
||||
|
||||
assert_equal Bukkits::Engine.instance, Rails::Engine.find(@plugin.path)
|
||||
|
||||
# check expanding paths
|
||||
engine_dir = @plugin.path.chomp("/").split("/").last
|
||||
engine_path = File.join(@plugin.path, '..', engine_dir)
|
||||
assert_equal Bukkits::Engine.instance, Rails::Engine.find(engine_path)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue