diff options
author | José Valim <jose.valim@gmail.com> | 2010-10-10 14:57:19 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-10-10 14:57:19 +0200 |
commit | 621df2a1ec01b77f7b052b3571f3c696f0443fea (patch) | |
tree | 089f0b4c7476e6ef9aa6b5c40bb399b08d398cea /railties/lib | |
parent | 49b6f33f99a28d68f18203a696fb47854a9085d2 (diff) | |
parent | a9bf91ea5640ab9ed9d6d7ba9da780ea1dfbd6e3 (diff) | |
download | rails-621df2a1ec01b77f7b052b3571f3c696f0443fea.tar.gz rails-621df2a1ec01b77f7b052b3571f3c696f0443fea.tar.bz2 rails-621df2a1ec01b77f7b052b3571f3c696f0443fea.zip |
Merge remote branch 'drogus/engines'
Diffstat (limited to 'railties/lib')
-rw-r--r-- | railties/lib/rails/engine.rb | 34 | ||||
-rw-r--r-- | railties/lib/rails/railtie.rb | 7 |
2 files changed, 31 insertions, 10 deletions
diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index f8caaef213..4acebb4769 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -214,11 +214,11 @@ module Rails # as they would be created inside application. One of the cosequences of that is including # application's helpers and url_helpers inside controller. Sometimes, especially when your # engine provides its own routes, you don't want that. To isolate engine's stuff from application - # you can use namespace method: + # you can use isolate_namespace method: # # module MyEngine # class Engine < Rails::Engine - # namespace MyEngine + # isolate_namespace MyEngine # end # end # @@ -252,7 +252,7 @@ module Rails # end # # - # Additionaly namespaced engine will set its name according to namespace, so in that case: + # Additionaly isolated engine will set its name according to namespace, so in that case: # MyEngine::Engine.engine_name #=> "my_engine" and it will set MyEngine.table_name_prefix # to "my_engine_". # @@ -315,7 +315,7 @@ module Rails autoload :Configuration, "rails/engine/configuration" class << self - attr_accessor :called_from, :namespaced + attr_accessor :called_from, :isolated alias :engine_name :railtie_name def inherited(base) @@ -350,12 +350,12 @@ module Rails @endpoint end - def namespace(mod) + def isolate_namespace(mod) engine_name(generate_railtie_name(mod)) name = engine_name self.routes.default_scope = {:module => name} - self.namespaced = true + self.isolated = true unless mod.respond_to?(:_railtie) _railtie = self @@ -371,13 +371,13 @@ module Rails end end - def namespaced? - !!namespaced + def isolated? + !!isolated end end delegate :middleware, :root, :paths, :to => :config - delegate :engine_name, :namespaced?, :to => "self.class" + delegate :engine_name, :isolated?, :to => "self.class" def load_tasks super @@ -506,7 +506,7 @@ module Rails end initializer :prepend_helpers_path do |app| - if !namespaced? || (app == self) + if !isolated? || (app == self) app.config.helpers_paths.unshift(*paths["app/helpers"].existent) end end @@ -522,6 +522,20 @@ module Rails # consistently executed after all the initializers above across all engines. end + rake_tasks do + next if self.is_a?(Rails::Application) + + namespace railtie_name do + namespace :install do + desc "Copy migrations from #{railtie_name} to application" + task :migrations do + ENV["FROM"] = railtie_name + Rake::Task["railties:install:migrations"].invoke + end + end + end + end + protected def routes? defined?(@routes) diff --git a/railties/lib/rails/railtie.rb b/railties/lib/rails/railtie.rb index 2b68a3c453..c76bc83377 100644 --- a/railties/lib/rails/railtie.rb +++ b/railties/lib/rails/railtie.rb @@ -191,6 +191,13 @@ module Rails def load_tasks self.class.rake_tasks.each(&:call) + + # load also tasks from all superclasses + klass = self.class.superclass + while klass.respond_to?(:rake_tasks) + klass.rake_tasks.each { |t| self.instance_exec(&t) } + klass = klass.superclass + end end def load_generators |