mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Refactor shebang to a class method, so other generators can use it.
This commit is contained in:
parent
748e1d6745
commit
7a8e284766
2 changed files with 24 additions and 15 deletions
|
@ -7,7 +7,6 @@ require 'thor'
|
|||
|
||||
module Rails
|
||||
module Generators
|
||||
|
||||
class Error < Thor::Error
|
||||
end
|
||||
|
||||
|
@ -26,7 +25,25 @@ module Rails
|
|||
File.expand_path(File.join(File.dirname(__FILE__), 'templates', klass_name.downcase))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Small macro to ruby as an option to the generator with proper default
|
||||
# value plus an instance helper method.
|
||||
#
|
||||
def self.add_shebang_option!
|
||||
require 'rbconfig'
|
||||
default = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'])
|
||||
|
||||
class_option :ruby, :type => :string, :aliases => "-r", :default => default,
|
||||
:desc => "Path to the Ruby binary of your choice"
|
||||
|
||||
class_eval do
|
||||
protected
|
||||
def shebang
|
||||
"#!#{options[:ruby] || "/usr/bin/env ruby"}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,22 +1,17 @@
|
|||
require File.dirname(__FILE__) + '/../base'
|
||||
require 'rbconfig'
|
||||
require 'digest/md5'
|
||||
require 'active_support/secure_random'
|
||||
|
||||
module Rails::Generators
|
||||
class App < Base
|
||||
namespace :rails
|
||||
DATABASES = %w( mysql oracle postgresql sqlite2 sqlite3 frontbase ibm_db )
|
||||
|
||||
DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'])
|
||||
DATABASES = %w( mysql oracle postgresql sqlite2 sqlite3 frontbase ibm_db )
|
||||
DEFAULT_DATABASE = 'sqlite3'
|
||||
namespace :rails
|
||||
add_shebang_option!
|
||||
|
||||
argument :app_path, :type => :string
|
||||
|
||||
class_option :ruby, :type => :string, :aliases => "-r", :default => DEFAULT_SHEBANG,
|
||||
:desc => "Path to the Ruby binary of your choice"
|
||||
|
||||
class_option :database, :type => :string, :aliases => "-d", :default => DEFAULT_DATABASE,
|
||||
class_option :database, :type => :string, :aliases => "-d", :default => "sqlite3",
|
||||
:desc => "Preconfigure for selected database (options: #{DATABASES.join('/')})"
|
||||
|
||||
class_option :freeze, :type => :boolean, :aliases => "-F", :default => false,
|
||||
|
@ -38,6 +33,7 @@ module Rails::Generators
|
|||
:desc => "Do not generate Prototype files"
|
||||
|
||||
# Add Rails options
|
||||
#
|
||||
class_option :version, :type => :boolean, :aliases => "-v", :group => :rails,
|
||||
:desc => "Show Rails version number and quit"
|
||||
|
||||
|
@ -185,10 +181,6 @@ module Rails::Generators
|
|||
ActiveSupport::SecureRandom.hex(64)
|
||||
end
|
||||
|
||||
def shebang
|
||||
"#!#{options[:ruby] || "/usr/bin/env ruby"}"
|
||||
end
|
||||
|
||||
def mysql_socket
|
||||
@mysql_socket ||= [
|
||||
"/tmp/mysql.sock", # default
|
||||
|
|
Loading…
Reference in a new issue