Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Some railties cleanup:

	* Rename <framework>/rails.rb -> <framework>/railtie.rb
	* Rails::Plugin -> Rails::Railtie
	* Rails::Plugin::Vendored -> Rails::Plugin
  • Loading branch information...
commit ae7ada1fde1648a5c81b9e6adf74d515e0bbe0a5 1 parent e749424
Carl Lerche authored
View
2  actionmailer/lib/action_mailer/rails.rb → actionmailer/lib/action_mailer/railtie.rb
@@ -2,7 +2,7 @@
require "rails"
module ActionMailer
- class Plugin < Rails::Plugin
+ class Railtie < Rails::Railtie
plugin_name :action_mailer
initializer "action_mailer.set_configs" do |app|
View
2  actionpack/lib/action_controller/rails.rb → actionpack/lib/action_controller/railtie.rb
@@ -2,7 +2,7 @@
require "rails"
module ActionController
- class Plugin < Rails::Plugin
+ class Railtie < Rails::Railtie
plugin_name :action_controller
initializer "action_controller.set_configs" do |app|
View
0  actionpack/lib/action_view/rails.rb → actionpack/lib/action_view/railtie.rb
File renamed without changes
View
0  activemodel/lib/active_model/rails.rb → activemodel/lib/active_model/railtie.rb
File renamed without changes
View
4 activerecord/lib/active_record/rails.rb → activerecord/lib/active_record/railtie.rb
@@ -3,11 +3,11 @@
# here. This is needed for correctly setting up the middleware.
# In the future, this might become an optional require.
require "active_record"
-require "action_controller/rails"
+require "action_controller/railtie"
require "rails"
module ActiveRecord
- class Plugin < Rails::Plugin
+ class Railtie < Rails::Railtie
plugin_name :active_record
rake_tasks do
View
0  activeresource/lib/active_resource/rails.rb → activeresource/lib/active_resource/railtie.rb
File renamed without changes
View
1  railties/lib/rails.rb
@@ -7,6 +7,7 @@
require 'rails/initializable'
require 'rails/application'
+require 'rails/railtie'
require 'rails/plugin'
require 'rails/railties_path'
require 'rails/version'
View
2  railties/lib/rails/all.rb
@@ -9,7 +9,7 @@
active_resource
).each do |framework|
begin
- require "#{framework}/rails"
+ require "#{framework}/railtie"
rescue LoadError
end
end
View
4 railties/lib/rails/application.rb
@@ -92,8 +92,8 @@ def initializers
def plugins
@plugins ||= begin
plugin_names = config.plugins || [:all]
- Plugin.plugins.select { |p| plugin_names.include?(:all) || plugin_names.include?(p.plugin_name) }.map { |p| p.new } +
- Plugin::Vendored.all(config.plugins || [:all], config.paths.vendor.plugins)
+ Railtie.plugins.select { |p| plugin_names.include?(:all) || plugin_names.include?(p.plugin_name) }.map { |p| p.new } +
+ Plugin.all(config.plugins || [:all], config.paths.vendor.plugins)
end
end
View
8 railties/lib/rails/configuration.rb
@@ -3,7 +3,7 @@
module Rails
# Temporarily separate the plugin configuration class from the main
# configuration class while this bit is being cleaned up.
- class Plugin::Configuration
+ class Railtie::Configuration
def self.default
@default ||= new
@@ -45,12 +45,12 @@ def config_key_regexp
end
def config_keys
- ([ :active_support, :action_view, :action_mailer, :active_resource ] +
- Plugin.plugin_names).map { |n| n.to_s }.uniq
+ ([ :active_support, :action_view ] +
+ Railtie.plugin_names).map { |n| n.to_s }.uniq
end
end
- class Configuration < Plugin::Configuration
+ class Configuration < Railtie::Configuration
attr_accessor :after_initialize_blocks, :cache_classes,
:consider_all_requests_local, :dependency_loading, :gems,
:load_once_paths, :logger, :metals, :plugins,
View
15 railties/lib/rails/generators/rails/app/templates/config/boot.rb
@@ -15,12 +15,11 @@
require 'rails/all'
# To pick the frameworks you want, remove 'require "rails/all"'
-# and list the frameworks that you want:
+# and list the framework railties that you want:
#
-# require "rails"
-# require "active_model/rails"
-# require "active_record/rails"
-# require "action_controller/rails"
-# require "action_view/rails"
-# require "action_mailer/rails"
-# require "active_resource/rails"
+# require "active_model/railtie"
+# require "active_record/railtie"
+# require "action_controller/railtie"
+# require "action_view/railtie"
+# require "action_mailer/railtie"
+# require "active_resource/railtie"
View
126 railties/lib/rails/plugin.rb
@@ -1,106 +1,64 @@
module Rails
- class Plugin
- include Initializable
-
- def self.plugin_name(plugin_name = nil)
- @plugin_name ||= name.demodulize.underscore
- @plugin_name = plugin_name if plugin_name
- @plugin_name
- end
-
- def self.inherited(klass)
- @plugins ||= []
- @plugins << klass unless klass == Vendored
- end
-
- def self.plugins
- @plugins
- end
+ 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
+ end
- def self.plugin_names
- plugins.map { |p| p.plugin_name }
+ plugins.sort_by do |p|
+ [list.index(p.name) || list.index(:all), p.name.to_s]
+ end
end
- def self.config
- Configuration.default
- end
+ attr_reader :name, :path
- def self.rake_tasks(&blk)
- @rake_tasks ||= []
- @rake_tasks << blk if blk
- @rake_tasks
+ def initialize(path)
+ @name = File.basename(path).to_sym
+ @path = path
end
- def rake_tasks
- self.class.rake_tasks
+ def load_paths
+ Dir["#{path}/{lib}", "#{path}/app/{models,controllers,helpers}"]
end
def load_tasks
- return unless rake_tasks
- rake_tasks.each { |blk| blk.call }
+ Dir["#{path}/**/tasks/**/*.rake"].sort.each { |ext| load ext }
end
- class Vendored < Plugin
- 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
- end
-
- plugins.sort_by do |p|
- [list.index(p.name) || list.index(:all), p.name.to_s]
- 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/**/*.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"
+ 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
+ ActiveSupport::Dependencies.load_paths << path
- unless app.config.reload_plugins
- ActiveSupport::Dependencies.load_once_paths << path
- end
+ unless app.config.reload_plugins
+ ActiveSupport::Dependencies.load_once_paths << path
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)
- 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)
+ end
- initializer :add_view_paths, :after => :initialize_framework_views do
- ActionController::Base.view_paths.concat ["#{path}/app/views"] if File.directory?("#{path}/app/views")
- end
+ initializer :add_view_paths, :after => :initialize_framework_views do
+ ActionController::Base.view_paths.concat ["#{path}/app/views"] if File.directory?("#{path}/app/views")
+ end
- initializer :add_routing_file, :after => :initialize_routing do |app|
- routing_file = "#{path}/config/routes.rb"
- if File.exist?(routing_file)
- app.route_configuration_files << routing_file
- app.reload_routes!
- end
+ initializer :add_routing_file, :after => :initialize_routing do |app|
+ routing_file = "#{path}/config/routes.rb"
+ if File.exist?(routing_file)
+ app.route_configuration_files << routing_file
+ app.reload_routes!
end
end
end
-end
+end
View
43 railties/lib/rails/railtie.rb
@@ -0,0 +1,43 @@
+module Rails
+ class Railtie
+ include Initializable
+
+ def self.plugin_name(plugin_name = nil)
+ @plugin_name ||= name.demodulize.underscore
+ @plugin_name = plugin_name if plugin_name
+ @plugin_name
+ end
+
+ def self.inherited(klass)
+ @plugins ||= []
+ @plugins << klass unless klass == Plugin
+ end
+
+ def self.plugins
+ @plugins
+ end
+
+ def self.plugin_names
+ plugins.map { |p| p.plugin_name }
+ end
+
+ def self.config
+ Configuration.default
+ end
+
+ def self.rake_tasks(&blk)
+ @rake_tasks ||= []
+ @rake_tasks << blk if blk
+ @rake_tasks
+ end
+
+ def rake_tasks
+ self.class.rake_tasks
+ end
+
+ def load_tasks
+ return unless rake_tasks
+ rake_tasks.each { |blk| blk.call }
+ end
+ end
+end
View
1  railties/test/application/configuration_test.rb
@@ -16,6 +16,7 @@ def setup
FileUtils.rm_rf(new_app) if File.directory?(new_app)
build_app
boot_rails
+ FileUtils.rm_rf("#{app_path}/config/environments")
end
test "the application root is set correctly" do
View
2  railties/test/application/initializer_test.rb
@@ -7,6 +7,7 @@ class InitializerTest < Test::Unit::TestCase
def setup
build_app
boot_rails
+ FileUtils.rm_rf "#{app_path}/config/environments"
end
test "initializing an application adds the application paths to the load path" do
@@ -160,6 +161,7 @@ class InitializerCustomFrameworkExtensionsTest < Test::Unit::TestCase
def setup
build_app
boot_rails
+ FileUtils.rm_rf "#{app_path}/config/environments"
end
test "database middleware doesn't initialize when activerecord is not in frameworks" do
View
1  railties/test/application/notifications_test.rb
@@ -18,6 +18,7 @@ class NotificationsTest < Test::Unit::TestCase
def setup
build_app
boot_rails
+ FileUtils.rm_rf("#{app_path}/config/environments")
require "active_support/notifications"
@events = []
View
2  railties/test/initializer/path_test.rb
@@ -7,6 +7,7 @@ class PathTest < Test::Unit::TestCase
def setup
build_app
boot_rails
+ FileUtils.rm_rf("#{app_path}/config/environments")
add_to_config <<-RUBY
config.root = "#{app_path}"
config.after_initialize do
@@ -14,7 +15,6 @@ def setup
end
RUBY
use_frameworks [:action_controller, :action_view, :action_mailer, :active_record]
- require "rails/all"
require "#{app_path}/config/environment"
@paths = Rails.application.config.paths
end
View
8 railties/test/plugins/configuration_test.rb
@@ -9,23 +9,23 @@ def setup
end
test "config is available to plugins" do
- class Foo < Rails::Plugin ; end
+ class Foo < Rails::Railtie ; end
assert_nil Foo.config.action_controller.foo
end
test "a config name is available for the plugin" do
- class Foo < Rails::Plugin ; config.foo.greetings = "hello" ; end
+ class Foo < Rails::Railtie ; config.foo.greetings = "hello" ; end
assert_equal "hello", Foo.config.foo.greetings
end
test "plugin configurations are available in the application" do
- class Foo < Rails::Plugin ; config.foo.greetings = "hello" ; end
+ class Foo < Rails::Railtie ; config.foo.greetings = "hello" ; end
require "#{app_path}/config/application"
assert_equal "hello", AppTemplate::Application.config.foo.greetings
end
test "plugin config merges are deep" do
- class Foo < Rails::Plugin ; config.foo.greetings = 'hello' ; end
+ class Foo < Rails::Railtie ; config.foo.greetings = 'hello' ; end
class MyApp < Rails::Application
config.foo.bar = "bar"
end
View
4 railties/test/plugins/framework_extension_test.rb
@@ -7,13 +7,14 @@ class FrameworkExtensionTest < Test::Unit::TestCase
def setup
build_app
boot_rails
+ FileUtils.rm_rf("#{app_path}/config/environments")
require "rails/all"
end
test "rake_tasks block is executed when MyApp.load_tasks is called" do
$ran_block = false
- class MyPlugin < Rails::Plugin
+ class MyTie < Rails::Railtie
rake_tasks do
$ran_block = true
end
@@ -37,6 +38,7 @@ class ActiveRecordExtensionTest < Test::Unit::TestCase
def setup
build_app
boot_rails
+ FileUtils.rm_rf("#{app_path}/config/environments")
end
test "active_record extensions are applied to ActiveRecord" do
Please sign in to comment.
Something went wrong with that request. Please try again.