Methods
- A
- B
- C
- D
- E
- G
- I
- J
- K
- N
- R
- S
Constants
DATABASES | = | %w( mysql oracle postgresql sqlite3 frontbase ibm_db sqlserver ) |
JDBC_DATABASES | = | %w( jdbcmysql jdbcsqlite3 jdbcpostgresql jdbc ) |
Attributes
[RW] | rails_template |
Class Public methods
# File railties/lib/rails/generators/app_base.rb, line 21 21: def self.add_shared_options_for(name) 22: class_option :builder, :type => :string, :aliases => "-b", 23: :desc => "Path to a #{name} builder (can be a filesystem path or URL)" 24: 25: class_option :template, :type => :string, :aliases => "-m", 26: :desc => "Path to an #{name} template (can be a filesystem path or URL)" 27: 28: class_option :skip_gemfile, :type => :boolean, :default => false, 29: :desc => "Don't create a Gemfile" 30: 31: class_option :skip_bundle, :type => :boolean, :default => false, 32: :desc => "Don't run bundle install" 33: 34: class_option :skip_git, :type => :boolean, :aliases => "-G", :default => false, 35: :desc => "Skip Git ignores and keeps" 36: 37: class_option :skip_active_record, :type => :boolean, :aliases => "-O", :default => false, 38: :desc => "Skip Active Record files" 39: 40: class_option :skip_sprockets, :type => :boolean, :aliases => "-S", :default => false, 41: :desc => "Skip Sprockets files" 42: 43: class_option :database, :type => :string, :aliases => "-d", :default => "sqlite3", 44: :desc => "Preconfigure for selected database (options: #{DATABASES.join('/')})" 45: 46: class_option :javascript, :type => :string, :aliases => '-j', :default => 'jquery', 47: :desc => 'Preconfigure for selected JavaScript library' 48: 49: class_option :skip_javascript, :type => :boolean, :aliases => "-J", :default => false, 50: :desc => "Skip JavaScript files" 51: 52: class_option :dev, :type => :boolean, :default => false, 53: :desc => "Setup the #{name} with Gemfile pointing to your Rails checkout" 54: 55: class_option :edge, :type => :boolean, :default => false, 56: :desc => "Setup the #{name} with Gemfile pointing to Rails repository" 57: 58: class_option :skip_test_unit, :type => :boolean, :aliases => "-T", :default => false, 59: :desc => "Skip Test::Unit files" 60: 61: class_option :help, :type => :boolean, :aliases => "-h", :group => :rails, 62: :desc => "Show this help message and quit" 63: 64: class_option :old_style_hash, :type => :boolean, :default => false, 65: :desc => "Force using old style hash (:foo => 'bar') on Ruby >= 1.9" 66: end
Instance Protected methods
# File railties/lib/rails/generators/app_base.rb, line 108 108: def apply_rails_template 109: apply rails_template if rails_template 110: rescue Thor::Error, LoadError, Errno::ENOENT => e 111: raise Error, "The template [#{rails_template}] could not be loaded. Error: #{e}" 112: end
# File railties/lib/rails/generators/app_base.rb, line 198 198: def assets_gemfile_entry 199: return if options[:skip_sprockets] 200: 201: gemfile = if options.dev? || options.edge? 202: "# Gems used only for assets and not required\n# in production environments by default.\ngroup :assets do\ngem 'sass-rails', :git => 'git://github.com/rails/sass-rails.git', :branch => '3-2-stable'\ngem 'coffee-rails', :git => 'git://github.com/rails/coffee-rails.git', :branch => '3-2-stable'\n\n# See https://github.com/sstephenson/execjs#readme for more supported runtimes\n\#{javascript_runtime_gemfile_entry}\ngem 'uglifier', '>= 1.0.3'\nend\n" 203: else 204: "# Gems used only for assets and not required\n# in production environments by default.\ngroup :assets do\ngem 'sass-rails', '~> 3.2.3'\ngem 'coffee-rails', '~> 3.2.1'\n\n# See https://github.com/sstephenson/execjs#readme for more supported runtimes\n\#{javascript_runtime_gemfile_entry}\ngem 'uglifier', '>= 1.0.3'\nend\n" 205: end 206: 207: gemfile.strip_heredoc.gsub(/^[ \t]*$/, '') 208: end
# File railties/lib/rails/generators/app_base.rb, line 76 76: def builder 77: @builder ||= begin 78: if path = options[:builder] 79: if URI(path).is_a?(URI::HTTP) 80: contents = open(path, "Accept" => "application/x-thor-template") {|io| io.read } 81: else 82: contents = open(File.expand_path(path, @original_wd)) {|io| io.read } 83: end 84: 85: prok = eval("proc { #{contents} }", TOPLEVEL_BINDING, path, 1) 86: instance_eval(&prok) 87: end 88: 89: builder_class = get_builder_class 90: builder_class.send(:include, ActionMethods) 91: builder_class.new(self) 92: end 93: end
# File railties/lib/rails/generators/app_base.rb, line 246 246: def bundle_command(command) 247: say_status :run, "bundle #{command}" 248: 249: # We are going to shell out rather than invoking Bundler::CLI.new(command) 250: # because `rails new` loads the Thor gem and on the other hand bundler uses 251: # its own vendored Thor, which could be a different version. Running both 252: # things in the same process is a recipe for a night with paracetamol. 253: # 254: # We use backticks and #print here instead of vanilla #system because it 255: # is easier to silence stdout in the existing test suite this way. The 256: # end-user gets the bundler commands called anyway, so no big deal. 257: # 258: # Thanks to James Tucker for the Gem tricks involved in this call. 259: print `"#{Gem.ruby}" -rubygems "#{Gem.bin_path('bundler', 'bundle')}" #{command}` 260: end
# File railties/lib/rails/generators/app_base.rb, line 179 179: def convert_database_option_for_jruby 180: if defined?(JRUBY_VERSION) 181: case options[:database] 182: when "oracle" then options[:database].replace "jdbc" 183: when "postgresql" then options[:database].replace "jdbcpostgresql" 184: when "mysql" then options[:database].replace "jdbcmysql" 185: when "sqlite3" then options[:database].replace "jdbcsqlite3" 186: end 187: end 188: end
# File railties/lib/rails/generators/app_base.rb, line 99 99: def create_root 100: self.destination_root = File.expand_path(app_path, destination_root) 101: valid_const? 102: 103: empty_directory '.' 104: set_default_accessors! 105: FileUtils.cd(destination_root) unless options[:pretend] 106: end
# File railties/lib/rails/generators/app_base.rb, line 163 163: def gem_for_database 164: # %w( mysql oracle postgresql sqlite3 frontbase ibm_db sqlserver jdbcmysql jdbcsqlite3 jdbcpostgresql ) 165: case options[:database] 166: when "oracle" then "ruby-oci8" 167: when "postgresql" then "pg" 168: when "frontbase" then "ruby-frontbase" 169: when "mysql" then "mysql2" 170: when "sqlserver" then "activerecord-sqlserver-adapter" 171: when "jdbcmysql" then "activerecord-jdbcmysql-adapter" 172: when "jdbcsqlite3" then "activerecord-jdbcsqlite3-adapter" 173: when "jdbcpostgresql" then "activerecord-jdbcpostgresql-adapter" 174: when "jdbc" then "activerecord-jdbc-adapter" 175: else options[:database] 176: end 177: end
Returns Ruby 1.9 style key-value pair if current code is running on Ruby 1.9.x. Returns the old-style (with hash rocket) otherwise.
# File railties/lib/rails/generators/app_base.rb, line 137 137: def rails_gemfile_entry 138: if options.dev? 139: "gem 'rails', :path => '\#{Rails::Generators::RAILS_DEV_PATH}'\ngem 'journey', :git => 'git://github.com/rails/journey.git'\ngem 'arel', :git => 'git://github.com/rails/arel.git', :branch => '3-0-stable'\n".strip_heredoc 140: elsif options.edge? 141: "gem 'rails', :git => 'git://github.com/rails/rails.git', :branch => '3-2-stable'\ngem 'journey', :git => 'git://github.com/rails/journey.git'\ngem 'arel', :git => 'git://github.com/rails/arel.git', :branch => '3-0-stable'\n".strip_heredoc 142: else 143: "gem 'rails', '\#{Rails::VERSION::STRING}'\n\n# Bundle edge Rails instead:\n# gem 'rails', :git => 'git://github.com/rails/rails.git'\n".strip_heredoc 144: end 145: end
# File railties/lib/rails/generators/app_base.rb, line 114 114: def set_default_accessors! 115: self.rails_template = case options[:template] 116: when /^https?:\/\// 117: options[:template] 118: when String 119: File.expand_path(options[:template], Dir.pwd) 120: else 121: options[:template] 122: end 123: end