Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

find railties and engines by name [4264 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
commit 7b8399b80cfff58cfe2313187ca3c803de8c8955 1 parent 5176b28
@joshsusser joshsusser authored josevalim committed
View
4 railties/lib/rails/railtie.rb
@@ -32,6 +32,10 @@ def railtie_names
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
View
17 railties/test/railties/railtie_test.rb
@@ -15,6 +15,23 @@ def app
@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
Please sign in to comment.
Something went wrong with that request. Please try again.