diff options
author | Josh Susser <josh@hasmanythrough.com> | 2010-03-24 23:12:32 -0700 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-03-26 14:25:45 +0100 |
commit | 7b8399b80cfff58cfe2313187ca3c803de8c8955 (patch) | |
tree | 4d1c3449e695e665cadc033d3513b03158bd2086 /railties | |
parent | 5176b28852dc6d0654cdf601d590bddbd6e6da1e (diff) | |
download | rails-7b8399b80cfff58cfe2313187ca3c803de8c8955.tar.gz rails-7b8399b80cfff58cfe2313187ca3c803de8c8955.tar.bz2 rails-7b8399b80cfff58cfe2313187ca3c803de8c8955.zip |
find railties and engines by name [4264 state:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'railties')
-rw-r--r-- | railties/lib/rails/railtie.rb | 4 | ||||
-rw-r--r-- | railties/test/railties/railtie_test.rb | 17 |
2 files changed, 21 insertions, 0 deletions
diff --git a/railties/lib/rails/railtie.rb b/railties/lib/rails/railtie.rb index 37c802fb60..be5d4ff260 100644 --- a/railties/lib/rails/railtie.rb +++ b/railties/lib/rails/railtie.rb @@ -32,6 +32,10 @@ module Rails subclasses.map { |p| p.railtie_name } end + def named(name) + subclasses.detect { |r| r.railtie_name == name } + end + def log_subscriber(log_subscriber) Rails::LogSubscriber.add(railtie_name, log_subscriber) end diff --git a/railties/test/railties/railtie_test.rb b/railties/test/railties/railtie_test.rb index 9fefb285b4..22fb0a2ec3 100644 --- a/railties/test/railties/railtie_test.rb +++ b/railties/test/railties/railtie_test.rb @@ -15,6 +15,23 @@ module RailtiesTest @app ||= Rails.application end + test "can find railtie by name" do + class TieA < Rails::Railtie; railtie_name :railtie_a; end + class TieB < Rails::Railtie; railtie_name :railtie_b; end + class EngineA < Rails::Engine; engine_name :engine_a; end + class EngineB < Rails::Engine; engine_name :engine_b; end + + assert_equal TieA, Rails::Railtie.named(:railtie_a) + assert_equal TieB, Rails::Railtie.named(:railtie_b) + assert_nil Rails::Railtie.named(:railtie_x) + assert_nil Rails::Railtie.named(:engine_a) + + assert_equal EngineA, Rails::Engine.named(:engine_a) + assert_equal EngineB, Rails::Engine.named(:engine_b) + assert_nil Rails::Engine.named(:engine_x) + assert_nil Rails::Engine.named(:railtie_a) + end + test "Rails::Railtie itself does not respond to config" do assert !Rails::Railtie.respond_to?(:config) end |