diff options
Diffstat (limited to 'railties/lib')
27 files changed, 167 insertions, 53 deletions
diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 6cd2c425c3..660e864d2a 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -48,6 +48,7 @@ module Rails # 10) Build the middleware stack and run to_prepare callbacks # 11) Run config.before_eager_load and eager_load if cache classes is true # 12) Run config.after_initialize callbacks + # class Application < Engine autoload :Bootstrap, 'rails/application/bootstrap' autoload :Configuration, 'rails/application/configuration' @@ -74,8 +75,12 @@ module Rails def initialize super - @initialized = false - @reloaders = [] + @initialized = false + @reloaders = [] + @routes_reloader = nil + @env_config = nil + @ordered_railties = nil + @queue = nil end # This method is called just after an application inherits from Rails::Application, @@ -92,7 +97,7 @@ module Rails # Rails application, you will need to add lib to $LOAD_PATH on your own in case # you need to load files in lib/ during the application configuration as well. def add_lib_to_load_path! #:nodoc: - path = config.root.join('lib').to_s + path = File.join config.root, 'lib' $LOAD_PATH.unshift(path) if File.exists?(path) end @@ -180,7 +185,7 @@ module Rails end all = (railties.all - order) - all.push(self) unless all.include?(self) + all.push(self) unless (all + order).include?(self) order.push(:all) unless order.include?(:all) index = order.index(:all) diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb index 84f2601f28..60aa40b92f 100644 --- a/railties/lib/rails/application/finisher.rb +++ b/railties/lib/rails/application/finisher.rb @@ -23,6 +23,8 @@ module Rails if Rails.env.development? app.routes.append do get '/rails/info/properties' => "rails/info#properties" + get '/rails/info/routes' => "rails/info#routes" + get '/rails/info' => "rails/info#index" end end end diff --git a/railties/lib/rails/application/route_inspector.rb b/railties/lib/rails/application/route_inspector.rb index b23fb3e920..942c4f4789 100644 --- a/railties/lib/rails/application/route_inspector.rb +++ b/railties/lib/rails/application/route_inspector.rb @@ -51,7 +51,7 @@ module Rails end def internal? - path =~ %r{/rails/info/properties|^#{Rails.application.config.assets.prefix}} + path =~ %r{/rails/info.*|^#{Rails.application.config.assets.prefix}} end def engine? diff --git a/railties/lib/rails/commands/console.rb b/railties/lib/rails/commands/console.rb index cd6a03fe51..b95df3e545 100644 --- a/railties/lib/rails/commands/console.rb +++ b/railties/lib/rails/commands/console.rb @@ -22,7 +22,7 @@ module Rails options = {} OptionParser.new do |opt| - opt.banner = "Usage: console [environment] [options]" + opt.banner = "Usage: rails console [environment] [options]" opt.on('-s', '--sandbox', 'Rollback database modifications on exit.') { |v| options[:sandbox] = v } opt.on("-e", "--environment=name", String, "Specifies the environment to run this console under (test/development/production).", diff --git a/railties/lib/rails/commands/dbconsole.rb b/railties/lib/rails/commands/dbconsole.rb index aaba47117f..cc7caffc3d 100644 --- a/railties/lib/rails/commands/dbconsole.rb +++ b/railties/lib/rails/commands/dbconsole.rb @@ -42,7 +42,7 @@ module Rails include_password = false options = {} OptionParser.new do |opt| - opt.banner = "Usage: dbconsole [environment] [options]" + opt.banner = "Usage: rails dbconsole [environment] [options]" opt.on("-p", "--include-password", "Automatically provide the password from database.yml") do |v| include_password = true end @@ -56,6 +56,11 @@ module Rails options['header'] = h end + opt.on("-h", "--help", "Show this help message.") do + puts opt + exit + end + opt.parse!(arguments) abort opt.to_s unless (0..1).include?(arguments.size) end @@ -96,7 +101,7 @@ module Rails args << "-#{options['mode']}" if options['mode'] args << "-header" if options['header'] - args << config['database'] + args << File.expand_path(config['database'], Rails.root) find_cmd_and_exec('sqlite3', *args) diff --git a/railties/lib/rails/commands/runner.rb b/railties/lib/rails/commands/runner.rb index 2802981e7a..77f1b15fb4 100644 --- a/railties/lib/rails/commands/runner.rb +++ b/railties/lib/rails/commands/runner.rb @@ -9,7 +9,7 @@ if ARGV.first.nil? end ARGV.clone.options do |opts| - opts.banner = "Usage: runner [options] ('Some.ruby(code)' or a filename)" + opts.banner = "Usage: rails runner [options] ('Some.ruby(code)' or a filename)" opts.separator "" diff --git a/railties/lib/rails/commands/server.rb b/railties/lib/rails/commands/server.rb index 4c4caad69f..e68d2e05c5 100644 --- a/railties/lib/rails/commands/server.rb +++ b/railties/lib/rails/commands/server.rb @@ -69,7 +69,7 @@ module Rails #Create required tmp directories if not found %w(cache pids sessions sockets).each do |dir_to_make| - FileUtils.mkdir_p(Rails.root.join('tmp', dir_to_make)) + FileUtils.mkdir_p(File.join(Rails.root, 'tmp', dir_to_make)) end unless options[:daemonize] diff --git a/railties/lib/rails/configuration.rb b/railties/lib/rails/configuration.rb index 57168eee83..5fa7f043c6 100644 --- a/railties/lib/rails/configuration.rb +++ b/railties/lib/rails/configuration.rb @@ -32,31 +32,32 @@ module Rails # And finally they can also be removed from the stack completely: # # config.middleware.delete ActionDispatch::BestStandardsSupport + # class MiddlewareStackProxy def initialize @operations = [] end def insert_before(*args, &block) - @operations << [:insert_before, args, block] + @operations << [__method__, args, block] end alias :insert :insert_before def insert_after(*args, &block) - @operations << [:insert_after, args, block] + @operations << [__method__, args, block] end def swap(*args, &block) - @operations << [:swap, args, block] + @operations << [__method__, args, block] end def use(*args, &block) - @operations << [:use, args, block] + @operations << [__method__, args, block] end def delete(*args, &block) - @operations << [:delete, args, block] + @operations << [__method__, args, block] end def merge_into(other) #:nodoc: diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index 47856c87c6..4c7199a2e2 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -340,6 +340,18 @@ module Rails autoload :Configuration, "rails/engine/configuration" autoload :Railties, "rails/engine/railties" + def initialize + @_all_autoload_paths = nil + @_all_load_paths = nil + @app = nil + @config = nil + @env_config = nil + @helpers = nil + @railties = nil + @routes = nil + super + end + def load_generators(app=self) initialize_generators railties.all { |r| r.load_generators(app) } @@ -404,9 +416,9 @@ module Rails # Finds engine with given path def find(path) - expanded_path = File.expand_path path.to_s + expanded_path = File.expand_path path Rails::Engine::Railties.engines.find { |engine| - File.expand_path(engine.root.to_s) == expanded_path + File.expand_path(engine.root) == expanded_path } end end @@ -615,14 +627,14 @@ module Rails end end - protected + protected def initialize_generators require "rails/generators" end def routes? - defined?(@routes) && @routes + @routes end def has_migrations? @@ -640,8 +652,7 @@ module Rails root = File.exist?("#{root_path}/#{flag}") ? root_path : default raise "Could not find root path for #{self}" unless root - RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ ? - Pathname.new(root).expand_path : Pathname.new(root).realpath + Pathname.new File.realpath root end def default_middleware_stack diff --git a/railties/lib/rails/engine/configuration.rb b/railties/lib/rails/engine/configuration.rb index f4de5a4375..e31df807a6 100644 --- a/railties/lib/rails/engine/configuration.rb +++ b/railties/lib/rails/engine/configuration.rb @@ -20,7 +20,7 @@ module Rails # Holds generators configuration: # # config.generators do |g| - # g.orm :datamapper, :migration => true + # g.orm :data_mapper, :migration => true # g.template_engine :haml # g.test_framework :rspec # end @@ -28,6 +28,7 @@ module Rails # If you want to disable color in console, do: # # config.generators.colorize_logging = false + # def generators #:nodoc: @generators ||= Rails::Configuration::Generators.new yield(@generators) if block_given? diff --git a/railties/lib/rails/generators/actions.rb b/railties/lib/rails/generators/actions.rb index 6cd2ea2bbd..c41acc7841 100644 --- a/railties/lib/rails/generators/actions.rb +++ b/railties/lib/rails/generators/actions.rb @@ -5,8 +5,7 @@ module Rails module Generators module Actions - # Adds an entry into Gemfile for the supplied gem. If env - # is specified, add the gem to the given environment. + # Adds an entry into Gemfile for the supplied gem. # # gem "rspec", :group => :test # gem "technoweenie-restful-authentication", :lib => "restful-authentication", :source => "http://gems.github.com/" @@ -27,7 +26,7 @@ module Rails log :gemfile, message options.each do |option, value| - parts << ":#{option} => #{value.inspect}" + parts << "#{option}: #{value.inspect}" end in_root do diff --git a/railties/lib/rails/generators/active_model.rb b/railties/lib/rails/generators/active_model.rb index 3d3b50540a..0e51b9c568 100644 --- a/railties/lib/rails/generators/active_model.rb +++ b/railties/lib/rails/generators/active_model.rb @@ -11,7 +11,7 @@ module Rails # ActiveRecord::Generators::ActiveModel.find(Foo, "params[:id]") # # => "Foo.find(params[:id])" # - # Datamapper::Generators::ActiveModel.find(Foo, "params[:id]") + # DataMapper::Generators::ActiveModel.find(Foo, "params[:id]") # # => "Foo.get(params[:id])" # # On initialization, the ActiveModel accepts the instance name that will @@ -22,6 +22,7 @@ module Rails # # The only exception in ActiveModel for ActiveRecord is the use of self.build # instead of self.new. + # class ActiveModel attr_reader :name diff --git a/railties/lib/rails/generators/base.rb b/railties/lib/rails/generators/base.rb index f2ded6be84..28d7680669 100644 --- a/railties/lib/rails/generators/base.rb +++ b/railties/lib/rails/generators/base.rb @@ -161,6 +161,7 @@ module Rails # hook_for :resource_controller do |instance, controller| # instance.invoke controller, [ instance.name.pluralize ] # end + # def self.hook_for(*names, &block) options = names.extract_options! in_base = options.delete(:in) || base_name diff --git a/railties/lib/rails/generators/named_base.rb b/railties/lib/rails/generators/named_base.rb index e02f19508f..63703176de 100644 --- a/railties/lib/rails/generators/named_base.rb +++ b/railties/lib/rails/generators/named_base.rb @@ -79,6 +79,10 @@ module Rails @class_path end + def namespaced_file_path + @namespaced_file_path ||= namespaced_class_path.join("/") + end + def namespaced_class_path @namespaced_class_path ||= begin namespace_path = namespace.name.split("::").map {|m| m.underscore } @@ -168,6 +172,7 @@ module Rails # # If the generator is invoked with class name Admin, it will check for # the presence of "AdminObserver". + # def self.check_class_collision(options={}) define_method :check_class_collision do name = if self.respond_to?(:controller_class_name) # for ScaffoldBase diff --git a/railties/lib/rails/generators/rails/app/templates/config/routes.rb b/railties/lib/rails/generators/rails/app/templates/config/routes.rb index 286e93c3cf..303e47877f 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/routes.rb +++ b/railties/lib/rails/generators/rails/app/templates/config/routes.rb @@ -1,6 +1,10 @@ <%= app_const %>.routes.draw do # The priority is based upon order of creation: # first created -> highest priority. + + # You can have the root of your site routed with "root" + # just remember to delete public/index.html. + # root :to => 'welcome#index' # Sample of regular route: # get 'products/:id' => 'catalog#view' @@ -46,9 +50,6 @@ # resources :products # end - # You can have the root of your site routed with "root" - # just remember to delete public/index.html. - # root :to => 'welcome#index' # See how all your routes lay out with "rake routes" end
\ No newline at end of file diff --git a/railties/lib/rails/generators/rails/controller/templates/controller.rb b/railties/lib/rails/generators/rails/controller/templates/controller.rb index 52243f4a2f..ece6bbba3b 100644 --- a/railties/lib/rails/generators/rails/controller/templates/controller.rb +++ b/railties/lib/rails/generators/rails/controller/templates/controller.rb @@ -1,3 +1,7 @@ +<% if namespaced? -%> +require_dependency "<%= namespaced_file_path %>/application_controller" +<% end -%> + <% module_namespacing do -%> class <%= class_name %>Controller < ApplicationController <% actions.each do |action| -%> diff --git a/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb b/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb index 722e37e20b..ab0e440bc4 100644 --- a/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb +++ b/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb @@ -139,7 +139,7 @@ task :default => :test gemfile_in_app_path = File.join(rails_app_path, "Gemfile") if File.exist? gemfile_in_app_path - entry = "gem '#{name}', :path => '#{relative_path}'" + entry = "gem '#{name}', path: '#{relative_path}'" append_file gemfile_in_app_path, entry end end @@ -232,6 +232,18 @@ task :default => :test public_task :apply_rails_template, :run_bundle + def name + @name ||= begin + # same as ActiveSupport::Inflector#underscore except not replacing '-' + underscored = original_name.dup + underscored.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2') + underscored.gsub!(/([a-z\d])([A-Z])/,'\1_\2') + underscored.downcase! + + underscored + end + end + protected def app_templates_dir @@ -268,18 +280,6 @@ task :default => :test @original_name ||= File.basename(destination_root) end - def name - @name ||= begin - # same as ActiveSupport::Inflector#underscore except not replacing '-' - underscored = original_name.dup - underscored.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2') - underscored.gsub!(/([a-z\d])([A-Z])/,'\1_\2') - underscored.downcase! - - underscored - end - end - def camelized @camelized ||= name.gsub(/\W/, '_').squeeze('_').camelize end diff --git a/railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb b/railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb index b95aea5f19..0294bde582 100644 --- a/railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb +++ b/railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb @@ -1,3 +1,7 @@ +<% if namespaced? -%> +require_dependency "<%= namespaced_file_path %>/application_controller" +<% end -%> + <% module_namespacing do -%> class <%= controller_class_name %>Controller < ApplicationController # GET <%= route_url %> diff --git a/railties/lib/rails/generators/resource_helpers.rb b/railties/lib/rails/generators/resource_helpers.rb index 3c12da359b..48833869e5 100644 --- a/railties/lib/rails/generators/resource_helpers.rb +++ b/railties/lib/rails/generators/resource_helpers.rb @@ -4,6 +4,7 @@ module Rails module Generators # Deal with controller names on scaffold and add some helpers to deal with # ActiveModel. + # module ResourceHelpers mattr_accessor :skip_warn @@ -12,6 +13,7 @@ module Rails end # Set controller variables on initialization. + # def initialize(*args) #:nodoc: super diff --git a/railties/lib/rails/generators/test_case.rb b/railties/lib/rails/generators/test_case.rb index e8f5925ca5..ff9cf0087e 100644 --- a/railties/lib/rails/generators/test_case.rb +++ b/railties/lib/rails/generators/test_case.rb @@ -26,6 +26,7 @@ module Rails # destination File.expand_path("../tmp", File.dirname(__FILE__)) # setup :prepare_destination # end + # class TestCase < ActiveSupport::TestCase include FileUtils @@ -42,6 +43,7 @@ module Rails # Sets which generator should be tested: # # tests AppGenerator + # def self.tests(klass) self.generator_class = klass end @@ -50,6 +52,7 @@ module Rails # invoking it. # # arguments %w(app_name --skip-active-record) + # def self.arguments(array) self.default_arguments = array end @@ -57,6 +60,7 @@ module Rails # Sets the destination of generator files: # # destination File.expand_path("../tmp", File.dirname(__FILE__)) + # def self.destination(path) self.destination_root = path end @@ -79,6 +83,7 @@ module Rails # assert_match(/Product\.all/, index) # end # end + # def assert_file(relative, *contents) absolute = File.expand_path(relative, destination_root) assert File.exists?(absolute), "Expected file #{relative.inspect} to exist, but does not" @@ -101,6 +106,7 @@ module Rails # path relative to the configured destination: # # assert_no_file "config/random.rb" + # def assert_no_file(relative) absolute = File.expand_path(relative, destination_root) assert !File.exists?(absolute), "Expected file #{relative.inspect} to not exist, but does" @@ -118,6 +124,7 @@ module Rails # assert_file "db/migrate/003_create_products.rb" # # Consequently, assert_migration accepts the same arguments has assert_file. + # def assert_migration(relative, *contents, &block) file_name = migration_file_name(relative) assert file_name, "Expected migration #{relative} to exist, but was not found" @@ -128,6 +135,7 @@ module Rails # path relative to the configured destination: # # assert_no_migration "db/migrate/create_products.rb" + # def assert_no_migration(relative) file_name = migration_file_name(relative) assert_nil file_name, "Expected migration #{relative} to not exist, but found #{file_name}" @@ -142,6 +150,7 @@ module Rails # assert_match(/create_table/, up) # end # end + # def assert_class_method(method, content, &block) assert_instance_method "self.#{method}", content, &block end @@ -154,6 +163,7 @@ module Rails # assert_match(/Product\.all/, index) # end # end + # def assert_instance_method(method, content) assert content =~ /def #{method}(\(.+\))?(.*?)\n end/m, "Expected to have method #{method}" yield $2.strip if block_given? @@ -164,6 +174,7 @@ module Rails # properly: # # assert_field_type :date, :date_select + # def assert_field_type(attribute_type, field_type) assert_equal(field_type, create_generated_attribute(attribute_type).field_type) end @@ -171,6 +182,7 @@ module Rails # Asserts the given attribute type gets a proper default value: # # assert_field_default_value :string, "MyString" + # def assert_field_default_value(attribute_type, value) assert_equal(value, create_generated_attribute(attribute_type).default) end @@ -204,6 +216,7 @@ module Rails # attribute type and, optionally, the attribute name: # # create_generated_attribute(:string, 'name') + # def create_generated_attribute(attribute_type, name = 'test', index = nil) Rails::Generators::GeneratedAttribute.parse([name, attribute_type, index].compact.join(':')) end diff --git a/railties/lib/rails/info_controller.rb b/railties/lib/rails/info_controller.rb index 6b4bdb2921..5081074395 100644 --- a/railties/lib/rails/info_controller.rb +++ b/railties/lib/rails/info_controller.rb @@ -1,15 +1,33 @@ +require 'rails/application/route_inspector' + class Rails::InfoController < ActionController::Base + self.view_paths = File.join(File.dirname(__FILE__), 'templates') + layout 'application' + + before_filter :require_local! + + def index + redirect_to '/rails/info/routes' + end + def properties - if consider_all_requests_local? || request.local? - render :inline => Rails::Info.to_html - else - render :text => '<p>For security purposes, this information is only available to local requests.</p>', :status => :forbidden - end + @info = Rails::Info.to_html + end + + def routes + inspector = Rails::Application::RouteInspector.new + @info = inspector.format(_routes.routes).join("\n") end protected - def consider_all_requests_local? - Rails.application.config.consider_all_requests_local + def require_local! + unless local_request? + render :text => '<p>For security purposes, this information is only available to local requests.</p>', :status => :forbidden + end + end + + def local_request? + Rails.application.config.consider_all_requests_local || request.local? end end diff --git a/railties/lib/rails/paths.rb b/railties/lib/rails/paths.rb index b787d91821..6cd9c7bc95 100644 --- a/railties/lib/rails/paths.rb +++ b/railties/lib/rails/paths.rb @@ -1,5 +1,3 @@ -require "pathname" - module Rails module Paths # This object is an extended hash that behaves as root of the <tt>Rails::Paths</tt> system. @@ -186,7 +184,7 @@ module Rails raise "You need to set a path root" unless @root.path map do |p| - Pathname.new(@root.path).join(p) + File.join @root.path, p end end diff --git a/railties/lib/rails/railtie.rb b/railties/lib/rails/railtie.rb index 8fbf58315a..2102f8a03c 100644 --- a/railties/lib/rails/railtie.rb +++ b/railties/lib/rails/railtie.rb @@ -110,6 +110,7 @@ module Rails # can be used in both. # # Be sure to look at the documentation of those specific classes for more information. + # class Railtie autoload :Configurable, "rails/railtie/configurable" autoload :Configuration, "rails/railtie/configuration" diff --git a/railties/lib/rails/tasks/engine.rake b/railties/lib/rails/tasks/engine.rake index eea8abe7d2..70370be3f5 100644 --- a/railties/lib/rails/tasks/engine.rake +++ b/railties/lib/rails/tasks/engine.rake @@ -60,7 +60,7 @@ namespace :db do end def find_engine_path(path) - return if path == "/" + return File.expand_path(Dir.pwd) if path == "/" if Rails::Engine.find(path) path diff --git a/railties/lib/rails/templates/layouts/application.html.erb b/railties/lib/rails/templates/layouts/application.html.erb new file mode 100644 index 0000000000..53276d3e7c --- /dev/null +++ b/railties/lib/rails/templates/layouts/application.html.erb @@ -0,0 +1,32 @@ +<!DOCTYPE html> +<html lang="en"> +<head> + <meta charset="utf-8" /> + <title>Routes</title> + <style> + body { background-color: #fff; color: #333; } + + body, p, ol, ul, td { + font-family: helvetica, verdana, arial, sans-serif; + font-size: 13px; + line-height: 18px; + } + + pre { + background-color: #eee; + padding: 10px; + font-size: 11px; + white-space: pre-wrap; + } + + a { color: #000; } + a:visited { color: #666; } + a:hover { color: #fff; background-color:#000; } + </style> +</head> +<body> +<h2>Your App: <%= link_to 'properties', '/rails/info/properties' %> | <%= link_to 'routes', '/rails/info/routes' %></h2> +<%= yield %> + +</body> +</html> diff --git a/railties/lib/rails/templates/rails/info/properties.html.erb b/railties/lib/rails/templates/rails/info/properties.html.erb new file mode 100644 index 0000000000..d47cbab202 --- /dev/null +++ b/railties/lib/rails/templates/rails/info/properties.html.erb @@ -0,0 +1 @@ +<%= @info.html_safe %>
\ No newline at end of file diff --git a/railties/lib/rails/templates/rails/info/routes.html.erb b/railties/lib/rails/templates/rails/info/routes.html.erb new file mode 100644 index 0000000000..890f6f5b03 --- /dev/null +++ b/railties/lib/rails/templates/rails/info/routes.html.erb @@ -0,0 +1,9 @@ +<h2> + Routes +</h2> + +<p> + Routes match in priority from top to bottom +</p> + +<p><pre><%= @info %></pre></p>
\ No newline at end of file |