diff options
author | rick <rick@spacemonkey.local> | 2008-05-10 17:46:55 -0700 |
---|---|---|
committer | rick <rick@spacemonkey.local> | 2008-05-10 17:46:55 -0700 |
commit | d09a8446d5606a5a0b5c024224b09a1318e9cf4d (patch) | |
tree | 199ef3554f731c980ea5726e67e34af4ea057c2e /railties | |
parent | c8451aeeea200043d8a3e6eae9c49def3a154ddb (diff) | |
parent | a7ea06b4ebe252e258f83e7de945b4baa30ec3bc (diff) | |
download | rails-d09a8446d5606a5a0b5c024224b09a1318e9cf4d.tar.gz rails-d09a8446d5606a5a0b5c024224b09a1318e9cf4d.tar.bz2 rails-d09a8446d5606a5a0b5c024224b09a1318e9cf4d.zip |
fix merge conflict with actionpack changelog
Diffstat (limited to 'railties')
-rw-r--r-- | railties/CHANGELOG | 2 | ||||
-rwxr-xr-x | railties/bin/dbconsole | 3 | ||||
-rw-r--r-- | railties/helpers/application.rb | 5 | ||||
-rw-r--r-- | railties/lib/commands/dbconsole.rb | 55 | ||||
-rw-r--r-- | railties/lib/initializer.rb | 8 | ||||
-rw-r--r-- | railties/lib/rails/plugin.rb | 16 | ||||
-rw-r--r-- | railties/lib/rails_generator/generators/applications/app/app_generator.rb | 2 | ||||
-rw-r--r-- | railties/lib/tasks/databases.rake | 11 |
8 files changed, 82 insertions, 20 deletions
diff --git a/railties/CHANGELOG b/railties/CHANGELOG index f52206d4d3..2ca1965d97 100644 --- a/railties/CHANGELOG +++ b/railties/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* script/dbconsole fires up the command-line database client. #102 [Steve Purcell] + * Fix bug where plugin init.rb files from frozen gem specs weren't being run. (pjb3) [#122 state:resolved] * Made the location of the routes file configurable with config.routes_configuration_file (Scott Fleckenstein) [#88] diff --git a/railties/bin/dbconsole b/railties/bin/dbconsole new file mode 100755 index 0000000000..caa60ce829 --- /dev/null +++ b/railties/bin/dbconsole @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +require File.dirname(__FILE__) + '/../config/boot' +require 'commands/dbconsole' diff --git a/railties/helpers/application.rb b/railties/helpers/application.rb index 9a79f69a41..0a3ed822a4 100644 --- a/railties/helpers/application.rb +++ b/railties/helpers/application.rb @@ -7,4 +7,9 @@ class ApplicationController < ActionController::Base # See ActionController::RequestForgeryProtection for details # Uncomment the :secret if you're not using the cookie session store protect_from_forgery # :secret => '<%= app_secret %>' + + # See ActionController::Base for details + # Uncomment this to filter the contents of submitted sensitive data parameters + # from your application log (in this case, all fields with names like "password"). + # filter_parameter_logging :password end diff --git a/railties/lib/commands/dbconsole.rb b/railties/lib/commands/dbconsole.rb new file mode 100644 index 0000000000..28c3a3e41f --- /dev/null +++ b/railties/lib/commands/dbconsole.rb @@ -0,0 +1,55 @@ +require 'yaml' +require 'optparse' + +OptionParser.new do |opt| + opt.banner = "Usage: dbconsole [environment]" + opt.parse!(ARGV) + abort opt.to_s unless (0..1).include?(ARGV.size) +end + +env = ARGV.first || ENV['RAILS_ENV'] || 'development' +unless config = YAML.load_file(RAILS_ROOT + "/config/database.yml")[env] + abort "No database is configured for the environment '#{env}'" +end + + +def find_cmd(*commands) + dirs_on_path = ENV['PATH'].to_s.split(File::PATH_SEPARATOR) + commands += commands.map{|cmd| "#{cmd}.exe"} if RUBY_PLATFORM =~ /win32/ + commands.detect do |cmd| + dirs_on_path.detect do |path| + File.executable? File.join(path, cmd) + end + end || abort("Couldn't find database client: #{commands.join(', ')}. Check your $PATH and try again.") +end + +case config["adapter"] +when "mysql" + args = { + 'host' => '--host', + 'port' => '--port', + 'socket' => '--socket', + 'username' => '--user', + 'password' => '--password', + 'encoding' => '--default-character-set' + }.map { |opt, arg| "#{arg}=#{config[opt]}" if config[opt] }.compact + + args << config['database'] + + exec(find_cmd('mysql5', 'mysql'), *args) + +when "postgresql" + ENV['PGHOST'] = config["host"] if config["host"] + ENV['PGPORT'] = config["port"].to_s if config["port"] + ENV['PGPASSWORD'] = config["password"].to_s if config["password"] + exec(find_cmd('psql'), '-U', config["username"], config["database"]) + +when "sqlite" + exec(find_cmd('sqlite'), config["database"]) + +when "sqlite3" + exec(find_cmd('sqlite3'), config["database"]) + +else + abort "Unknown command-line client for #{config['database']}. Submit a Rails patch to add support!" +end diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 6db96f0158..dfd43042be 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -572,11 +572,13 @@ module Rails attr_accessor :plugin_loader # Enables or disables plugin reloading. You can get around this setting per plugin. - # If <tt>reload_plugins?</tt> is false, add this to your plugin's init.rb to make it reloadable: + # If <tt>reload_plugins?</tt> is false, add this to your plugin's <tt>init.rb</tt> + # to make it reloadable: # # Dependencies.load_once_paths.delete lib_path # - # If <tt>reload_plugins?</tt> is true, add this to your plugin's init.rb to only load it once: + # If <tt>reload_plugins?</tt> is true, add this to your plugin's <tt>init.rb</tt> + # to only load it once: # # Dependencies.load_once_paths << lib_path # @@ -676,7 +678,7 @@ module Rails YAML::load(ERB.new(IO.read(database_configuration_file)).result) end - # The path to the current environment's file (development.rb, etc.). By + # The path to the current environment's file (<tt>development.rb</tt>, etc.). By # default the file is at <tt>config/environments/#{environment}.rb</tt>. def environment_path "#{root_path}/config/environments/#{environment}.rb" diff --git a/railties/lib/rails/plugin.rb b/railties/lib/rails/plugin.rb index b45ec7de0e..04f7e37a20 100644 --- a/railties/lib/rails/plugin.rb +++ b/railties/lib/rails/plugin.rb @@ -1,14 +1,14 @@ module Rails # The Plugin class should be an object which provides the following methods: # - # * +name+ - used during initialisation to order the plugin (based on name and - # the contents of <tt>config.plugins</tt>) - # * +valid?+ - returns true if this plugin can be loaded - # * +load_paths+ - each path within the returned array will be added to the $LOAD_PATH - # * +load+ - finally 'load' the plugin. + # * +name+ - Used during initialisation to order the plugin (based on name and + # the contents of <tt>config.plugins</tt>). + # * +valid?+ - Returns true if this plugin can be loaded. + # * +load_paths+ - Each path within the returned array will be added to the <tt>$LOAD_PATH</tt>. + # * +load+ - Finally 'load' the plugin. # # These methods are expected by the Rails::Plugin::Locator and Rails::Plugin::Loader classes. - # The default implementation returns the <tt>lib</tt> directory as its </tt>load_paths</tt>, + # The default implementation returns the <tt>lib</tt> directory as its <tt>load_paths</tt>, # and evaluates <tt>init.rb</tt> when <tt>load</tt> is called. # # You can also inspect the about.yml data programmatically: @@ -31,13 +31,13 @@ module Rails File.directory?(directory) && (has_lib_directory? || has_init_file?) end - # Returns a list of paths this plugin wishes to make available in $LOAD_PATH + # Returns a list of paths this plugin wishes to make available in <tt>$LOAD_PATH</tt>. def load_paths report_nonexistant_or_empty_plugin! unless valid? has_lib_directory? ? [lib_path] : [] end - # Evaluates a plugin's init.rb file + # Evaluates a plugin's init.rb file. def load(initializer) return if loaded? report_nonexistant_or_empty_plugin! unless valid? diff --git a/railties/lib/rails_generator/generators/applications/app/app_generator.rb b/railties/lib/rails_generator/generators/applications/app/app_generator.rb index 85c417f7cd..2f2dd82682 100644 --- a/railties/lib/rails_generator/generators/applications/app/app_generator.rb +++ b/railties/lib/rails_generator/generators/applications/app/app_generator.rb @@ -72,7 +72,7 @@ class AppGenerator < Rails::Generator::Base m.file "environments/test.rb", "config/environments/test.rb" # Scripts - %w( about console destroy generate performance/benchmarker performance/profiler performance/request process/reaper process/spawner process/inspector runner server plugin ).each do |file| + %w( about console dbconsole destroy generate performance/benchmarker performance/profiler performance/request process/reaper process/spawner process/inspector runner server plugin ).each do |file| m.file "bin/#{file}", "script/#{file}", script_options end diff --git a/railties/lib/tasks/databases.rake b/railties/lib/tasks/databases.rake index 20fdcce205..63f71448f8 100644 --- a/railties/lib/tasks/databases.rake +++ b/railties/lib/tasks/databases.rake @@ -46,7 +46,7 @@ namespace :db do @encoding = config[:encoding] || ENV['CHARSET'] || 'utf8' begin ActiveRecord::Base.establish_connection(config.merge('database' => 'template1')) - ActiveRecord::Base.connection.create_database(config['database'], :encoding => @encoding) + ActiveRecord::Base.connection.create_database(config['database'], config.merge('encoding' => @encoding)) ActiveRecord::Base.establish_connection(config) rescue $stderr.puts $!, *($!.backtrace) @@ -314,14 +314,9 @@ namespace :db do ActiveRecord::Base.establish_connection(:test) ActiveRecord::Base.connection.recreate_database(abcs["test"]["database"]) when "postgresql" - ENV['PGHOST'] = abcs["test"]["host"] if abcs["test"]["host"] - ENV['PGPORT'] = abcs["test"]["port"].to_s if abcs["test"]["port"] - ENV['PGPASSWORD'] = abcs["test"]["password"].to_s if abcs["test"]["password"] - enc_option = "-E #{abcs["test"]["encoding"]}" if abcs["test"]["encoding"] - ActiveRecord::Base.clear_active_connections! - `dropdb -U "#{abcs["test"]["username"]}" #{abcs["test"]["database"]}` - `createdb #{enc_option} -U "#{abcs["test"]["username"]}" #{abcs["test"]["database"]}` + drop_database(abcs['test']) + create_database(abcs['test']) when "sqlite","sqlite3" dbfile = abcs["test"]["database"] || abcs["test"]["dbfile"] File.delete(dbfile) if File.exist?(dbfile) |