Add Rails::Railtie.railtie_name method to allow setting custom name for railtie

This commit is contained in:
Piotr Sarnacki
2010-07-26 17:05:04 +02:00
parent b52dfc6726
commit bfccbc6df9
4 changed files with 19 additions and 2 deletions

View File

@@ -277,8 +277,13 @@ module ActionDispatch
private
def app_name(app)
return unless app.respond_to?(:routes)
class_name = app.class.is_a?(Class) ? app.name : app.class.name
ActiveSupport::Inflector.underscore(class_name).gsub("/", "_")
if app.respond_to?(:railtie_name)
app.railtie_name
else
class_name = app.class.is_a?(Class) ? app.name : app.class.name
ActiveSupport::Inflector.underscore(class_name).gsub("/", "_")
end
end
def define_generate_prefix(app, name)

View File

@@ -48,6 +48,10 @@ module Rails
attr_reader :name, :path
def railtie_name
name.to_s
end
def load_tasks
super
load_deprecated_tasks

View File

@@ -164,8 +164,15 @@ module Rails
def abstract_railtie?
ABSTRACT_RAILTIES.include?(name)
end
def railtie_name(name = nil)
@railtie_name = name if name
@railtie_name ||= ActiveSupport::Inflector.underscore(self.name).gsub("/", "_")
end
end
delegate :railtie_name, :to => "self.class"
def config
@config ||= Railtie::Configuration.new
end

View File

@@ -28,6 +28,7 @@ module RailtiesTest
plugin.write "lib/bukkits.rb", <<-RUBY
class Bukkits
class Engine < ::Rails::Engine
railtie_name "bukkits"
end
end
RUBY