aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2010-03-26 14:41:40 +0100
committerJosé Valim <jose.valim@gmail.com>2010-03-26 14:41:48 +0100
commitf5ee855f439feb7958504dc1d8e62aad4da5fac6 (patch)
treee2694372e490478a6c9c594f4b6cfb9756ec3974
parent7b8399b80cfff58cfe2313187ca3c803de8c8955 (diff)
downloadrails-f5ee855f439feb7958504dc1d8e62aad4da5fac6.tar.gz
rails-f5ee855f439feb7958504dc1d8e62aad4da5fac6.tar.bz2
rails-f5ee855f439feb7958504dc1d8e62aad4da5fac6.zip
Improve heuristic for railties default name, otherwise railties may be named :railtie, :engine and so on.
-rw-r--r--railties/lib/rails/engine.rb2
-rw-r--r--railties/lib/rails/railtie.rb17
-rw-r--r--railties/test/railties/railtie_test.rb8
3 files changed, 19 insertions, 8 deletions
diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb
index 85b4ff8470..e4888cdef7 100644
--- a/railties/lib/rails/engine.rb
+++ b/railties/lib/rails/engine.rb
@@ -14,7 +14,7 @@ module Rails
alias :engine_names :railtie_names
def inherited(base)
- unless abstract_railtie?(base)
+ unless base.abstract_railtie?
base.called_from = begin
# Remove the line number from backtraces making sure we don't leave anything behind
call_stack = caller.map { |p| p.split(':')[0..-2].join(':') }
diff --git a/railties/lib/rails/railtie.rb b/railties/lib/rails/railtie.rb
index be5d4ff260..b7f6c02503 100644
--- a/railties/lib/rails/railtie.rb
+++ b/railties/lib/rails/railtie.rb
@@ -9,7 +9,8 @@ module Rails
include Initializable
- ABSTRACT_RAILTIES = %w(Rails::Plugin Rails::Engine Rails::Application)
+ ABSTRACT_RAILTIES = %w(Rails::Railtie Rails::Plugin Rails::Engine Rails::Application)
+ RAILTIES_TYPES = ABSTRACT_RAILTIES.map { |r| r.split('::').last }
class << self
def subclasses
@@ -17,7 +18,7 @@ module Rails
end
def inherited(base)
- unless abstract_railtie?(base)
+ unless base.abstract_railtie?
base.send(:include, self::Configurable)
subclasses << base
end
@@ -52,14 +53,16 @@ module Rails
@generators
end
- protected
-
- def abstract_railtie?(base)
- ABSTRACT_RAILTIES.include?(base.name)
+ def abstract_railtie?
+ ABSTRACT_RAILTIES.include?(name)
end
+ protected
+
def default_name
- ActiveSupport::Inflector.underscore(ActiveSupport::Inflector.demodulize(name))
+ namespaces = name.split("::")
+ namespaces.pop if RAILTIES_TYPES.include?(namespaces.last)
+ ActiveSupport::Inflector.underscore(namespaces.last).to_sym
end
end
diff --git a/railties/test/railties/railtie_test.rb b/railties/test/railties/railtie_test.rb
index 22fb0a2ec3..9283482893 100644
--- a/railties/test/railties/railtie_test.rb
+++ b/railties/test/railties/railtie_test.rb
@@ -15,6 +15,14 @@ module RailtiesTest
@app ||= Rails.application
end
+ test "name can be retrieved from namespaced railties" do
+ module ActiveRailtie
+ class Railtie < Rails::Railtie; end
+ end
+
+ assert_equal :active_railtie, ActiveRailtie::Railtie.railtie_name
+ 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