diff options
Diffstat (limited to 'railties/lib')
-rw-r--r-- | railties/lib/rails.rb | 2 | ||||
-rw-r--r-- | railties/lib/rails/application.rb | 1 | ||||
-rw-r--r-- | railties/lib/rails/configuration.rb | 15 | ||||
-rw-r--r-- | railties/lib/rails/engine.rb | 11 | ||||
-rw-r--r-- | railties/lib/rails/plugin.rb | 78 |
5 files changed, 46 insertions, 61 deletions
diff --git a/railties/lib/rails.rb b/railties/lib/rails.rb index 29afb672b6..667587cdce 100644 --- a/railties/lib/rails.rb +++ b/railties/lib/rails.rb @@ -6,8 +6,8 @@ require 'active_support/core_ext/logger' require 'rails/initializable' require 'rails/railtie' -require 'rails/plugin' require 'rails/engine' +require 'rails/plugin' require 'rails/application' require 'rails/railties_path' require 'rails/version' diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 1286d437c7..6d1702bf93 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -36,7 +36,6 @@ module Rails base.rake_tasks do require "rails/tasks" - paths.lib.tasks.to_a.sort.each { |r| load(rake) } task :environment do $rails_rake_task = true initialize! diff --git a/railties/lib/rails/configuration.rb b/railties/lib/rails/configuration.rb index b8bed01cdc..900173abcc 100644 --- a/railties/lib/rails/configuration.rb +++ b/railties/lib/rails/configuration.rb @@ -125,19 +125,19 @@ module Rails attr_reader :root attr_writer :eager_load_paths, :load_once_paths, :load_paths - def initialize(root) + def initialize(root=nil) @root = root - super() end def paths @paths ||= begin paths = Rails::Application::Root.new(@root) - paths.app "app", :eager_load => true, :glob => "*" - paths.app.controllers "app/controllers", :eager_load => true - paths.app.metals "app/metal", :eager_load => true + paths.app "app", :eager_load => true, :glob => "*" + paths.app.controllers "app/controllers", :eager_load => true + paths.app.metals "app/metal", :eager_load => true paths.app.views "app/views" - paths.lib "lib", :load_path => true + paths.lib "lib", :load_path => true + paths.lib.tasks "lib/tasks", :glob => "**/*.rake" paths.config "config" paths.config.environment "config/environments", :glob => "#{Rails.env}.rb" paths.config.initializers "config/initializers", :glob => "**/*.rb" @@ -183,7 +183,6 @@ module Rails paths = super paths.app.controllers << builtin_controller if builtin_controller paths.config.database "config/database.yml" - paths.lib.tasks "lib/tasks", :glob => "**/*.rake" paths.log "log/#{Rails.env}.log" paths.tmp "tmp" paths.tmp.cache "tmp/cache" @@ -215,7 +214,7 @@ module Rails self.preload_frameworks = true self.cache_classes = true self.dependency_loading = false - action_controller.allow_concurrency = true if respond_to?(:action_controller) + self.action_controller.allow_concurrency = true if respond_to?(:action_controller) self end diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index b11c1ac73e..39afac0604 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -40,12 +40,21 @@ module Rails end end - delegate :middleware, :paths, :root, :config, :to => :'self.class' + delegate :middleware, :paths, :root, :to => :config + + def config + self.class.config + end def reloadable?(app) app.config.reload_plugins end + def load_tasks + super + config.paths.lib.tasks.to_a.sort.each { |ext| load(ext) } + end + # Add configured load paths to ruby load paths and remove duplicates. initializer :set_load_path do config.load_paths.reverse_each do |path| diff --git a/railties/lib/rails/plugin.rb b/railties/lib/rails/plugin.rb index 43632127fc..b4fd503631 100644 --- a/railties/lib/rails/plugin.rb +++ b/railties/lib/rails/plugin.rb @@ -1,67 +1,45 @@ module Rails - class Plugin < Railtie - def self.all(list, paths) - plugins = [] - paths.each do |path| - Dir["#{path}/*"].each do |plugin_path| - plugin = new(plugin_path) - next unless list.include?(plugin.name) || list.include?(:all) - plugins << plugin - end + class Plugin < Engine + class << self + def inherited(base) + raise "You should not inherit from Rails::Plugin" end - plugins.sort_by do |p| - [list.index(p.name) || list.index(:all), p.name.to_s] + def config + raise "Plugins does not provide configuration at the class level" end - end - - attr_reader :name, :path - - def initialize(path) - @name = File.basename(path).to_sym - @path = path - end - - def load_paths - Dir["#{path}/{lib}", "#{path}/app/{models,controllers,helpers}"] - end - - def load_tasks - Dir["#{path}/{tasks,lib/tasks,rails/tasks}/**/*.rake"].sort.each { |ext| load ext } - end - - initializer :add_to_load_path, :after => :set_autoload_paths do |app| - load_paths.each do |path| - $LOAD_PATH << path - require "active_support/dependencies" - ActiveSupport::Dependencies.load_paths << path + def all(list, paths) + plugins = [] + paths.each do |path| + Dir["#{path}/*"].each do |plugin_path| + plugin = new(plugin_path) + next unless list.include?(plugin.name) || list.include?(:all) + plugins << plugin + end + end - unless app.config.reload_plugins - ActiveSupport::Dependencies.load_once_paths << path + plugins.sort_by do |p| + [list.index(p.name) || list.index(:all), p.name.to_s] end end end - initializer :load_init_rb, :before => :load_application_initializers do |app| - file = "#{@path}/init.rb" - config = app.config - eval File.read(file), binding, file if File.file?(file) + attr_reader :name, :path + + def initialize(root) + @name = File.basename(root).to_sym + config.root = root end - initializer :add_view_paths, :after => :initialize_framework_views do - plugin_views = "#{path}/app/views" - if File.directory?(plugin_views) - ActionController::Base.view_paths.concat([plugin_views]) if defined? ActionController - ActionMailer::Base.view_paths.concat([plugin_views]) if defined? ActionMailer - end + def config + @config ||= Engine::Configuration.new end - initializer :add_routing_file, :after => :initialize_routing do |app| - routing_file = "#{path}/config/routes.rb" - if File.exist?(routing_file) - app.config.action_dispatch.route_files.unshift(routing_file) - end + initializer :load_init_rb do |app| + file = Dir["#{root}/{rails/init,init}.rb"].first + config = app.config + eval(File.read(file), binding, file) if file && File.file?(file) end end end |