From 7fcf8590e788cef8b64cc266f75931c418902ca9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 21 Jan 2010 23:14:20 +0100 Subject: Massive cleanup in Railties and load stack. --- railties/lib/rails/engine.rb | 107 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 railties/lib/rails/engine.rb (limited to 'railties/lib/rails/engine.rb') diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb new file mode 100644 index 0000000000..21c78036bd --- /dev/null +++ b/railties/lib/rails/engine.rb @@ -0,0 +1,107 @@ +require 'active_support/core_ext/module/delegation' + +module Rails + # TODO Move I18n and views path setup + class Engine < Railtie + + class << self + attr_accessor :called_from + + def root + @root ||= find_root_with_file_flag("lib") + end + + def config + @config ||= Configuration.new(root) + end + + def inherited(base) + base.called_from = begin + call_stack = caller.map { |p| p.split(':').first } + File.dirname(call_stack.detect { |p| p !~ %r[railties/lib/rails|rack/lib/rack] }) + end + super + end + + protected + + def find_root_with_file_flag(flag, default=nil) + root_path = self.called_from + + while root_path && File.directory?(root_path) && !File.exist?("#{root_path}/#{flag}") + parent = File.dirname(root_path) + root_path = parent != root_path && parent + end + + root = File.exist?("#{root_path}/flag") ? root_path : default + + raise "Could not find root path for #{self}" unless root + + RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? + Pathname.new(root).expand_path : + Pathname.new(root).realpath + end + end + + delegate :root, :config, :to => :'self.class' + delegate :middleware, :to => :config + + # Add configured load paths to ruby load paths and remove duplicates. + initializer :set_load_path, :before => :container do + config.paths.add_to_load_path + $LOAD_PATH.uniq! + end + + # Set the paths from which Rails will automatically load source files, + # and the load_once paths. + initializer :set_autoload_paths, :before => :container do + require 'active_support/dependencies' + + ActiveSupport::Dependencies.load_paths = expand_load_path(config.load_paths) + ActiveSupport::Dependencies.load_once_paths = expand_load_path(config.load_once_paths) + + extra = ActiveSupport::Dependencies.load_once_paths - ActiveSupport::Dependencies.load_paths + + unless extra.empty? + abort <<-end_error + load_once_paths must be a subset of the load_paths. + Extra items in load_once_paths: #{extra * ','} + end_error + end + + # Freeze the arrays so future modifications will fail rather than do nothing mysteriously + config.load_once_paths.freeze + end + + initializer :load_application_initializers do + Dir["#{root}/config/initializers/**/*.rb"].sort.each do |initializer| + load(initializer) + end + end + + # Routing must be initialized after plugins to allow the former to extend the routes + initializer :initialize_routing do |app| + app.route_configuration_files.concat(config.paths.config.routes.to_a) + end + + # Eager load application classes + initializer :load_application_classes do |app| + next if $rails_rake_task + + if app.config.cache_classes + config.eager_load_paths.each do |load_path| + matcher = /\A#{Regexp.escape(load_path)}(.*)\.rb\Z/ + Dir.glob("#{load_path}/**/*.rb").sort.each do |file| + require_dependency file.sub(matcher, '\1') + end + end + end + end + + private + + def expand_load_path(load_paths) + load_paths.map { |path| Dir.glob(path.to_s) }.flatten.uniq + end + end +end \ No newline at end of file -- cgit v1.2.3 From 02c5137eadbb3530033d919b7aebeb6f4f389b83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 22 Jan 2010 01:10:31 +0100 Subject: Add view paths to Engine setup. --- railties/lib/rails/engine.rb | 48 +++++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 16 deletions(-) (limited to 'railties/lib/rails/engine.rb') diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index 21c78036bd..a0139f9983 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -1,18 +1,19 @@ require 'active_support/core_ext/module/delegation' module Rails - # TODO Move I18n and views path setup + # TODO Move I18n here + # TODO Set routes namespaces class Engine < Railtie class << self attr_accessor :called_from - def root - @root ||= find_root_with_file_flag("lib") + def original_root + @original_root ||= find_root_with_file_flag("lib") end def config - @config ||= Configuration.new(root) + @config ||= Configuration.new(original_root) end def inherited(base) @@ -20,6 +21,7 @@ module Rails call_stack = caller.map { |p| p.split(':').first } File.dirname(call_stack.detect { |p| p !~ %r[railties/lib/rails|rack/lib/rack] }) end + super end @@ -33,7 +35,7 @@ module Rails root_path = parent != root_path && parent end - root = File.exist?("#{root_path}/flag") ? root_path : default + root = File.exist?("#{root_path}/#{flag}") ? root_path : default raise "Could not find root path for #{self}" unless root @@ -43,8 +45,8 @@ module Rails end end - delegate :root, :config, :to => :'self.class' - delegate :middleware, :to => :config + delegate :config, :to => :'self.class' + delegate :middleware, :root, :to => :config # Add configured load paths to ruby load paths and remove duplicates. initializer :set_load_path, :before => :container do @@ -57,10 +59,11 @@ module Rails initializer :set_autoload_paths, :before => :container do require 'active_support/dependencies' - ActiveSupport::Dependencies.load_paths = expand_load_path(config.load_paths) + ActiveSupport::Dependencies.load_paths = expand_load_path(config.load_paths) ActiveSupport::Dependencies.load_once_paths = expand_load_path(config.load_once_paths) - extra = ActiveSupport::Dependencies.load_once_paths - ActiveSupport::Dependencies.load_paths + extra = ActiveSupport::Dependencies.load_once_paths - + ActiveSupport::Dependencies.load_paths unless extra.empty? abort <<-end_error @@ -73,15 +76,24 @@ module Rails config.load_once_paths.freeze end - initializer :load_application_initializers do - Dir["#{root}/config/initializers/**/*.rb"].sort.each do |initializer| - load(initializer) - end + # Routing must be initialized after plugins to allow the former to extend the routes + initializer :add_routing_files do |app| + routes = select_existing(config.paths.config.routes) + app.route_configuration_files.concat(routes) end - # Routing must be initialized after plugins to allow the former to extend the routes - initializer :initialize_routing do |app| - app.route_configuration_files.concat(config.paths.config.routes.to_a) + initializer :add_view_paths do + views = select_existing(config.paths.app.views) + ActionController::Base.view_paths.concat(views) if defined? ActionController + ActionMailer::Base.view_paths.concat(views) if defined? ActionMailer + end + + initializer :load_application_initializers do + select_existing(config.paths.config.initializers).each do |initializers| + Dir["#{initializers}/**/*.rb"].sort.each do |initializer| + load(initializer) + end + end end # Eager load application classes @@ -100,6 +112,10 @@ module Rails private + def select_existing(paths) + paths.to_a.select { |path| File.exists?(path) }.uniq + end + def expand_load_path(load_paths) load_paths.map { |path| Dir.glob(path.to_s) }.flatten.uniq end -- cgit v1.2.3 From 4ae79367277954bf6616151b03cbe0660808f9bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 22 Jan 2010 16:24:44 +0100 Subject: Got tests working once again. --- railties/lib/rails/engine.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'railties/lib/rails/engine.rb') diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index a0139f9983..effbfee6c1 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -50,7 +50,9 @@ module Rails # Add configured load paths to ruby load paths and remove duplicates. initializer :set_load_path, :before => :container do - config.paths.add_to_load_path + expand_load_path(config.load_paths).reverse_each do |path| + $LOAD_PATH.unshift(path) if File.directory?(path) + end $LOAD_PATH.uniq! end -- cgit v1.2.3 From 98240c49b05093d6d14b9384a9bd695b58eefb59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 23 Jan 2010 01:29:29 +0100 Subject: Get rid of initializers global and create i18n railtie. --- railties/lib/rails/engine.rb | 48 +++++++++++++++++--------------------------- 1 file changed, 18 insertions(+), 30 deletions(-) (limited to 'railties/lib/rails/engine.rb') diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index effbfee6c1..93f39f176c 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -4,7 +4,6 @@ module Rails # TODO Move I18n here # TODO Set routes namespaces class Engine < Railtie - class << self attr_accessor :called_from @@ -49,8 +48,8 @@ module Rails delegate :middleware, :root, :to => :config # Add configured load paths to ruby load paths and remove duplicates. - initializer :set_load_path, :before => :container do - expand_load_path(config.load_paths).reverse_each do |path| + initializer :set_load_path do + config.load_paths.reverse_each do |path| $LOAD_PATH.unshift(path) if File.directory?(path) end $LOAD_PATH.uniq! @@ -58,11 +57,9 @@ module Rails # Set the paths from which Rails will automatically load source files, # and the load_once paths. - initializer :set_autoload_paths, :before => :container do - require 'active_support/dependencies' - - ActiveSupport::Dependencies.load_paths = expand_load_path(config.load_paths) - ActiveSupport::Dependencies.load_once_paths = expand_load_path(config.load_once_paths) + initializer :set_autoload_paths do + ActiveSupport::Dependencies.load_paths.concat(config.load_paths) + ActiveSupport::Dependencies.load_once_paths.concat(config.load_once_paths) extra = ActiveSupport::Dependencies.load_once_paths - ActiveSupport::Dependencies.load_paths @@ -74,31 +71,32 @@ module Rails end_error end - # Freeze the arrays so future modifications will fail rather than do nothing mysteriously + # Freeze so future modifications will fail rather than do nothing mysteriously config.load_once_paths.freeze end - # Routing must be initialized after plugins to allow the former to extend the routes initializer :add_routing_files do |app| - routes = select_existing(config.paths.config.routes) - app.route_configuration_files.concat(routes) + config.paths.config.routes.to_a.each do |route| + app.route_configuration_files << route if File.exists?(route) + end + end + + initializer :add_locales do + config.i18n.load_path.concat(config.paths.config.locales.to_a) end initializer :add_view_paths do - views = select_existing(config.paths.app.views) - ActionController::Base.view_paths.concat(views) if defined? ActionController - ActionMailer::Base.view_paths.concat(views) if defined? ActionMailer + views = config.paths.app.views.to_a + ActionController::Base.view_paths.concat(views) if defined?(ActionController) + ActionMailer::Base.view_paths.concat(views) if defined?(ActionMailer) end initializer :load_application_initializers do - select_existing(config.paths.config.initializers).each do |initializers| - Dir["#{initializers}/**/*.rb"].sort.each do |initializer| - load(initializer) - end + config.paths.config.initializers.each do |initializer| + load(initializer) end end - # Eager load application classes initializer :load_application_classes do |app| next if $rails_rake_task @@ -111,15 +109,5 @@ module Rails end end end - - private - - def select_existing(paths) - paths.to_a.select { |path| File.exists?(path) }.uniq - end - - def expand_load_path(load_paths) - load_paths.map { |path| Dir.glob(path.to_s) }.flatten.uniq - end end end \ No newline at end of file -- cgit v1.2.3 From 4eab3aad8d256b868390b739b075bd38661339b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 23 Jan 2010 02:03:11 +0100 Subject: Ensure user set load paths have higher preference and move Bootstrap inside Application. --- railties/lib/rails/engine.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/lib/rails/engine.rb') diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index 93f39f176c..03c78b6d4b 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -77,12 +77,12 @@ module Rails initializer :add_routing_files do |app| config.paths.config.routes.to_a.each do |route| - app.route_configuration_files << route if File.exists?(route) + app.route_configuration_files.unshift(route) if File.exists?(route) end end initializer :add_locales do - config.i18n.load_path.concat(config.paths.config.locales.to_a) + config.i18n.load_path.unshift(*config.paths.config.locales.to_a) end initializer :add_view_paths do -- cgit v1.2.3 From 80130d1201c3bf9dc17b0e1fcd81c6b22e893b0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 23 Jan 2010 15:05:13 +0100 Subject: Extract routes reloading responsibilities from application and load them just upon a request. --- railties/lib/rails/engine.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'railties/lib/rails/engine.rb') diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index 03c78b6d4b..aaa669ef32 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -1,8 +1,6 @@ require 'active_support/core_ext/module/delegation' module Rails - # TODO Move I18n here - # TODO Set routes namespaces class Engine < Railtie class << self attr_accessor :called_from @@ -75,9 +73,9 @@ module Rails config.load_once_paths.freeze end - initializer :add_routing_files do |app| + initializer :add_routing_files do config.paths.config.routes.to_a.each do |route| - app.route_configuration_files.unshift(route) if File.exists?(route) + config.action_dispatch.route_files.unshift(route) if File.exists?(route) end end -- cgit v1.2.3 From 13d66cdf2544af0d465d596383743b16b5005996 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 23 Jan 2010 16:59:32 +0100 Subject: Extract Railtie load from application. --- railties/lib/rails/engine.rb | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'railties/lib/rails/engine.rb') diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index aaa669ef32..cf6ca7c3f5 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -4,6 +4,7 @@ module Rails class Engine < Railtie class << self attr_accessor :called_from + delegate :middleware, :root, :paths, :to => :config def original_root @original_root ||= find_root_with_file_flag("lib") @@ -18,7 +19,6 @@ module Rails call_stack = caller.map { |p| p.split(':').first } File.dirname(call_stack.detect { |p| p !~ %r[railties/lib/rails|rack/lib/rack] }) end - super end @@ -33,17 +33,14 @@ module Rails end root = File.exist?("#{root_path}/#{flag}") ? root_path : default - raise "Could not find root path for #{self}" unless root RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? - Pathname.new(root).expand_path : - Pathname.new(root).realpath + Pathname.new(root).expand_path : Pathname.new(root).realpath end end - delegate :config, :to => :'self.class' - delegate :middleware, :root, :to => :config + delegate :middleware, :paths, :root, :config, :to => :'self.class' # Add configured load paths to ruby load paths and remove duplicates. initializer :set_load_path do -- cgit v1.2.3 From 924fa084e81b8b2f5ae9eab93d6b711c2b6b89d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 23 Jan 2010 17:13:25 +0100 Subject: First steps into making Plugin < Engine. --- railties/lib/rails/engine.rb | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'railties/lib/rails/engine.rb') diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index cf6ca7c3f5..b11c1ac73e 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -42,6 +42,10 @@ module Rails delegate :middleware, :paths, :root, :config, :to => :'self.class' + def reloadable?(app) + app.config.reload_plugins + end + # Add configured load paths to ruby load paths and remove duplicates. initializer :set_load_path do config.load_paths.reverse_each do |path| @@ -52,21 +56,17 @@ module Rails # Set the paths from which Rails will automatically load source files, # and the load_once paths. - initializer :set_autoload_paths do + initializer :set_autoload_paths do |app| ActiveSupport::Dependencies.load_paths.concat(config.load_paths) - ActiveSupport::Dependencies.load_once_paths.concat(config.load_once_paths) - - extra = ActiveSupport::Dependencies.load_once_paths - - ActiveSupport::Dependencies.load_paths - unless extra.empty? - abort <<-end_error - load_once_paths must be a subset of the load_paths. - Extra items in load_once_paths: #{extra * ','} - end_error + if reloadable?(app) + ActiveSupport::Dependencies.load_once_paths.concat(config.load_once_paths) + else + ActiveSupport::Dependencies.load_once_paths.concat(config.load_paths) end # Freeze so future modifications will fail rather than do nothing mysteriously + config.load_paths.freeze config.load_once_paths.freeze end -- cgit v1.2.3 From 2b75b94ac0c329de12a0a94ba77f8aad5574514f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 23 Jan 2010 17:51:48 +0100 Subject: Plugin is now an Engine. --- railties/lib/rails/engine.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'railties/lib/rails/engine.rb') 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| -- cgit v1.2.3 From 788fce2550ed587d86d239d8fcd488f919d15b5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 23 Jan 2010 18:41:53 +0100 Subject: Create configurable modules and ensure that they are added only on direct children. --- railties/lib/rails/engine.rb | 38 +++++++++++++++----------------------- 1 file changed, 15 insertions(+), 23 deletions(-) (limited to 'railties/lib/rails/engine.rb') diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index 39afac0604..b373b931f9 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -2,29 +2,23 @@ require 'active_support/core_ext/module/delegation' module Rails class Engine < Railtie + autoload :Configurable, "rails/engine/configurable" + class << self attr_accessor :called_from - delegate :middleware, :root, :paths, :to => :config - - def original_root - @original_root ||= find_root_with_file_flag("lib") - end - - def config - @config ||= Configuration.new(original_root) - end def inherited(base) - base.called_from = begin - call_stack = caller.map { |p| p.split(':').first } - File.dirname(call_stack.detect { |p| p !~ %r[railties/lib/rails|rack/lib/rack] }) + unless abstract_railtie?(base) + base.called_from = begin + call_stack = caller.map { |p| p.split(':').first } + File.dirname(call_stack.detect { |p| p !~ %r[railties/lib/rails|rack/lib/rack] }) + end end + super end - protected - - def find_root_with_file_flag(flag, default=nil) + def find_root_with_flag(flag, default=nil) root_path = self.called_from while root_path && File.directory?(root_path) && !File.exist?("#{root_path}/#{flag}") @@ -42,14 +36,6 @@ module Rails 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) } @@ -113,5 +99,11 @@ module Rails end end end + + protected + + def reloadable?(app) + app.config.reload_plugins + end end end \ No newline at end of file -- cgit v1.2.3 From b17e358e3df34c03019e357f693611618092e1d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 23 Jan 2010 22:30:17 +0100 Subject: Move configuration to subfolders. --- railties/lib/rails/engine.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'railties/lib/rails/engine.rb') diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index b373b931f9..d972050dc9 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -1,8 +1,10 @@ require 'active_support/core_ext/module/delegation' +require 'rails/railtie' module Rails class Engine < Railtie - autoload :Configurable, "rails/engine/configurable" + autoload :Configurable, "rails/engine/configurable" + autoload :Configuration, "rails/engine/configuration" class << self attr_accessor :called_from -- cgit v1.2.3 From 2fde9d774b322fc708990675671231c64c691a33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 24 Jan 2010 09:00:18 +0100 Subject: Solve some pendencies. --- railties/lib/rails/engine.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/lib/rails/engine.rb') diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index d972050dc9..cc878ac8f2 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -67,9 +67,9 @@ module Rails config.load_once_paths.freeze end - initializer :add_routing_files do + initializer :add_routing_paths do config.paths.config.routes.to_a.each do |route| - config.action_dispatch.route_files.unshift(route) if File.exists?(route) + config.action_dispatch.route_paths.unshift(route) if File.exists?(route) end end -- cgit v1.2.3 From e0bdc4f446686a498c3117e27ed8561f5c6d34f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 24 Jan 2010 11:06:06 +0100 Subject: Ensure namespaced controllers in engines work. --- railties/lib/rails/engine.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'railties/lib/rails/engine.rb') diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index cc878ac8f2..6f724963b2 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -73,6 +73,16 @@ module Rails end end + initializer :add_routing_namespaces do |app| + config.paths.app.controllers.to_a.each do |load_path| + load_path = File.expand_path(load_path) + Dir["#{load_path}/*/*_controller.rb"].collect do |path| + namespace = File.dirname(path).sub(/#{load_path}\/?/, '') + app.routes.controller_namespaces << namespace unless namespace.empty? + end + end + end + initializer :add_locales do config.i18n.load_path.unshift(*config.paths.config.locales.to_a) end -- cgit v1.2.3 From e548f96b1d5cb6529dd6fbc6544f03a3a840b48c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 24 Jan 2010 12:23:21 +0100 Subject: Rename plugin_name to railtie_name and engine_name. --- railties/lib/rails/engine.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'railties/lib/rails/engine.rb') diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index 6f724963b2..842785875a 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -9,6 +9,9 @@ module Rails class << self attr_accessor :called_from + alias :engine_name :railtie_name + alias :engine_names :railtie_names + def inherited(base) unless abstract_railtie?(base) base.called_from = begin -- cgit v1.2.3 From 84ebfa4550b2325c6c89bc13aa6f904ff88d0db7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 24 Jan 2010 14:48:00 +0100 Subject: Ensure metals and initializers in plugins are loaded. --- railties/lib/rails/engine.rb | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'railties/lib/rails/engine.rb') diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index 842785875a..e40052e0f1 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -71,13 +71,13 @@ module Rails end initializer :add_routing_paths do - config.paths.config.routes.to_a.each do |route| - config.action_dispatch.route_paths.unshift(route) if File.exists?(route) + paths.config.routes.to_a.each do |route| + Rails::Application::RoutesReloader.paths.unshift(route) if File.exists?(route) end end initializer :add_routing_namespaces do |app| - config.paths.app.controllers.to_a.each do |load_path| + paths.app.controllers.to_a.each do |load_path| load_path = File.expand_path(load_path) Dir["#{load_path}/*/*_controller.rb"].collect do |path| namespace = File.dirname(path).sub(/#{load_path}\/?/, '') @@ -87,17 +87,21 @@ module Rails end initializer :add_locales do - config.i18n.load_path.unshift(*config.paths.config.locales.to_a) + config.i18n.load_path.unshift(*paths.config.locales.to_a) end initializer :add_view_paths do - views = config.paths.app.views.to_a + views = paths.app.views.to_a ActionController::Base.view_paths.concat(views) if defined?(ActionController) ActionMailer::Base.view_paths.concat(views) if defined?(ActionMailer) end + initializer :add_metals do + Rails::Rack::Metal.paths.concat(paths.app.metals.to_a) + end + initializer :load_application_initializers do - config.paths.config.initializers.each do |initializer| + paths.config.initializers.to_a.sort.each do |initializer| load(initializer) end end @@ -107,7 +111,7 @@ module Rails if app.config.cache_classes config.eager_load_paths.each do |load_path| - matcher = /\A#{Regexp.escape(load_path)}(.*)\.rb\Z/ + matcher = /\A#{Regexp.escape(load_path)}\/(.*)\.rb\Z/ Dir.glob("#{load_path}/**/*.rb").sort.each do |file| require_dependency file.sub(matcher, '\1') end -- cgit v1.2.3