diff options
author | Piotr Sarnacki <drogus@gmail.com> | 2010-08-03 22:36:12 +0200 |
---|---|---|
committer | Piotr Sarnacki <drogus@gmail.com> | 2010-09-03 22:59:11 +0200 |
commit | db8a864e693034b5a0d03396a0c297d5557862ed (patch) | |
tree | aacb7b4cec213abd8e01d94f027b2b2735c0f876 | |
parent | a7c6fe4c2a577bd7e9871aa4746d70c0984325db (diff) | |
download | rails-db8a864e693034b5a0d03396a0c297d5557862ed.tar.gz rails-db8a864e693034b5a0d03396a0c297d5557862ed.tar.bz2 rails-db8a864e693034b5a0d03396a0c297d5557862ed.zip |
Add table_name_prefix to Engine's namespace automatically
-rw-r--r-- | railties/lib/rails/engine.rb | 8 | ||||
-rw-r--r-- | railties/lib/rails/railtie.rb | 7 | ||||
-rw-r--r-- | railties/test/railties/engine_test.rb | 2 |
3 files changed, 16 insertions, 1 deletions
diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index 13629e0de3..663feb4e32 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -201,11 +201,19 @@ module Rails end def namespace(mod) + # TODO: extract that into a module + engine_name(generate_railtie_name(mod)) + _railtie = self + name = engine_name mod.singleton_class.instance_eval do define_method(:_railtie) do _railtie end + + define_method(:table_name_prefix) do + "#{name}_" + end end end end diff --git a/railties/lib/rails/railtie.rb b/railties/lib/rails/railtie.rb index ab565b0cdc..09650789ac 100644 --- a/railties/lib/rails/railtie.rb +++ b/railties/lib/rails/railtie.rb @@ -167,8 +167,13 @@ module Rails def railtie_name(name = nil) @railtie_name = name.to_s if name - @railtie_name ||= ActiveSupport::Inflector.underscore(self.name).gsub("/", "_") + @railtie_name ||= generate_railtie_name(self.name) end + + protected + def generate_railtie_name(class_or_module) + ActiveSupport::Inflector.underscore(class_or_module).gsub("/", "_") + end end delegate :railtie_name, :to => "self.class" diff --git a/railties/test/railties/engine_test.rb b/railties/test/railties/engine_test.rb index c845843095..47a38d7aeb 100644 --- a/railties/test/railties/engine_test.rb +++ b/railties/test/railties/engine_test.rb @@ -408,6 +408,8 @@ module RailtiesTest boot_rails + assert_equal "bukkits_", Bukkits.table_name_prefix + assert_equal "bukkits", Bukkits::Engine.engine_name assert_equal Bukkits._railtie, Bukkits::Engine assert ::Bukkits::MyMailer.method_defined?(:foo_path) assert !::Bukkits::MyMailer.method_defined?(:bar_path) |