From f9640b090019d9cff899b28a8c8d4f638ad04acb Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Thu, 23 Apr 2015 13:05:30 +1000 Subject: Remove redundant 'Rails' from Rails::AppRailsLoader constant --- guides/source/initialization.md | 6 +-- railties/lib/rails/app_loader.rb | 64 ++++++++++++++++++++++++ railties/lib/rails/app_rails_loader.rb | 64 ------------------------ railties/lib/rails/cli.rb | 2 +- railties/test/app_loader_test.rb | 89 ++++++++++++++++++++++++++++++++++ railties/test/app_rails_loader_test.rb | 89 ---------------------------------- 6 files changed, 157 insertions(+), 157 deletions(-) create mode 100644 railties/lib/rails/app_loader.rb delete mode 100644 railties/lib/rails/app_rails_loader.rb create mode 100644 railties/test/app_loader_test.rb delete mode 100644 railties/test/app_rails_loader_test.rb diff --git a/guides/source/initialization.md b/guides/source/initialization.md index 199545a3b3..c0cd3a1640 100644 --- a/guides/source/initialization.md +++ b/guides/source/initialization.md @@ -53,11 +53,11 @@ require "rails/cli" ``` The file `railties/lib/rails/cli` in turn calls -`Rails::AppRailsLoader.exec_app_rails`. +`Rails::AppLoader.exec_app`. -### `railties/lib/rails/app_rails_loader.rb` +### `railties/lib/rails/app_loader.rb` -The primary goal of the function `exec_app_rails` is to execute your app's +The primary goal of the function `exec_app` is to execute your app's `bin/rails`. If the current directory does not have a `bin/rails`, it will navigate upwards until it finds a `bin/rails` executable. Thus one can invoke a `rails` command from anywhere inside a rails application. diff --git a/railties/lib/rails/app_loader.rb b/railties/lib/rails/app_loader.rb new file mode 100644 index 0000000000..a9fe21824e --- /dev/null +++ b/railties/lib/rails/app_loader.rb @@ -0,0 +1,64 @@ +require 'pathname' +require 'rails/version' + +module Rails + module AppLoader # :nodoc: + extend self + + RUBY = Gem.ruby + EXECUTABLES = ['bin/rails', 'script/rails'] + BUNDLER_WARNING = < private/var. + assert_equal File.realpath("#@tmp/foo"), File.realpath(Dir.pwd) + end + end + end + + teardown do + Dir.chdir(@cwd) + FileUtils.rm_rf(@tmp) + end +end diff --git a/railties/test/app_rails_loader_test.rb b/railties/test/app_rails_loader_test.rb deleted file mode 100644 index d4885447e6..0000000000 --- a/railties/test/app_rails_loader_test.rb +++ /dev/null @@ -1,89 +0,0 @@ -require 'tmpdir' -require 'abstract_unit' -require 'rails/app_rails_loader' - -class AppRailsLoaderTest < ActiveSupport::TestCase - def loader - @loader ||= Class.new do - extend Rails::AppRailsLoader - - def self.exec_arguments - @exec_arguments - end - - def self.exec(*args) - @exec_arguments = args - end - end - end - - def write(filename, contents=nil) - FileUtils.mkdir_p(File.dirname(filename)) - File.write(filename, contents) - end - - def expects_exec(exe) - assert_equal [Rails::AppRailsLoader::RUBY, exe], loader.exec_arguments - end - - setup do - @tmp = Dir.mktmpdir('railties-rails-loader-test-suite') - @cwd = Dir.pwd - Dir.chdir(@tmp) - end - - ['bin', 'script'].each do |script_dir| - exe = "#{script_dir}/rails" - - test "is not in a Rails application if #{exe} is not found in the current or parent directories" do - def loader.find_executables; end - - assert !loader.exec_app_rails - end - - test "is not in a Rails application if #{exe} exists but is a folder" do - FileUtils.mkdir_p(exe) - - assert !loader.exec_app_rails - end - - ['APP_PATH', 'ENGINE_PATH'].each do |keyword| - test "is in a Rails application if #{exe} exists and contains #{keyword}" do - write exe, keyword - - loader.exec_app_rails - - expects_exec exe - end - - test "is not in a Rails application if #{exe} exists but doesn't contain #{keyword}" do - write exe - - assert !loader.exec_app_rails - end - - test "is in a Rails application if parent directory has #{exe} containing #{keyword} and chdirs to the root directory" do - write "foo/bar/#{exe}" - write "foo/#{exe}", keyword - - Dir.chdir('foo/bar') - - loader.exec_app_rails - - expects_exec exe - - # Compare the realpath in case either of them has symlinks. - # - # This happens in particular in Mac OS X, where @tmp starts - # with "/var", and Dir.pwd with "/private/var", due to a - # default system symlink var -> private/var. - assert_equal File.realpath("#@tmp/foo"), File.realpath(Dir.pwd) - end - end - end - - teardown do - Dir.chdir(@cwd) - FileUtils.rm_rf(@tmp) - end -end -- cgit v1.2.3