diff options
author | José Valim <jose.valim@gmail.com> | 2009-11-02 23:46:00 -0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2009-11-02 23:46:00 -0200 |
commit | d002826e54415a340e55fdbf363d005faebf8fc5 (patch) | |
tree | 431146dfb0b15c4507fd49bb7d6f18bd40ccf839 /railties/lib/rails | |
parent | 9ba83cce0318fa5051764f4a16c286adf30169e2 (diff) | |
parent | 14370e1aab6ddfb5b86cf50bd7e5abcebae0684c (diff) | |
download | rails-d002826e54415a340e55fdbf363d005faebf8fc5.tar.gz rails-d002826e54415a340e55fdbf363d005faebf8fc5.tar.bz2 rails-d002826e54415a340e55fdbf363d005faebf8fc5.zip |
Merge branch 'master' of git://github.com/rails/rails
Diffstat (limited to 'railties/lib/rails')
78 files changed, 323 insertions, 1163 deletions
diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index a0e5d6a5a5..26a55a73e1 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -3,6 +3,11 @@ module Rails extend Initializable class << self + # Stub out App initialize + def initialize! + new + end + def config @config ||= Configuration.new end @@ -36,13 +41,13 @@ module Rails end def new - initializers.run + run_initializers self end end initializer :initialize_rails do - Rails.initializers.run + Rails.run_initializers end # Set the <tt>$LOAD_PATH</tt> based on the value of @@ -52,13 +57,6 @@ module Rails $LOAD_PATH.uniq! end - # Bail if boot.rb is outdated - initializer :freak_out_if_boot_rb_is_outdated do - unless defined?(Rails::BOOTSTRAP_VERSION) - abort %{Your config/boot.rb is outdated: Run "rake rails:update".} - end - end - # Requires all frameworks specified by the Configuration#frameworks # list. By default, all frameworks (Active Record, Active Support, # Action Pack, Action Mailer, and Active Resource) are loaded. @@ -128,15 +126,6 @@ module Rails end end - initializer :add_gem_load_paths do - require 'rails/gem_dependency' - Rails::GemDependency.add_frozen_gem_path - unless config.gems.empty? - require "rubygems" - config.gems.each { |gem| gem.add_load_paths } - end - end - # Preload all frameworks specified by the Configuration#frameworks. # Used by Passenger to ensure everything's loaded before forking and # to avoid autoload race conditions in JRuby. @@ -322,31 +311,6 @@ module Rails end end - initializer :check_for_unbuilt_gems do - unbuilt_gems = config.gems.select {|gem| gem.frozen? && !gem.built? } - if unbuilt_gems.size > 0 - # don't print if the gems:build rake tasks are being run - unless $gems_build_rake_task - abort <<-end_error - The following gems have native components that need to be built - #{unbuilt_gems.map { |gemm| "#{gemm.name} #{gemm.requirement}" } * "\n "} - - You're running: - ruby #{Gem.ruby_version} at #{Gem.ruby} - rubygems #{Gem::RubyGemsVersion} at #{Gem.path * ', '} - - Run `rake gems:build` to build the unbuilt gems. - end_error - end - end - end - - initializer :load_gems do - unless $gems_rake_task - config.gems.each { |gem| gem.load } - end - end - # Loads all plugins in <tt>config.plugin_paths</tt>. <tt>plugin_paths</tt> # defaults to <tt>vendor/plugins</tt> but may also be set to a list of # paths, such as @@ -367,49 +331,19 @@ module Rails plugin_loader.load_plugins end - # TODO: Figure out if this needs to run a second time - # load_gems - - initializer :check_gem_dependencies do - unloaded_gems = config.gems.reject { |g| g.loaded? } - if unloaded_gems.size > 0 - configuration.gems_dependencies_loaded = false - # don't print if the gems rake tasks are being run - unless $gems_rake_task - abort <<-end_error - Missing these required gems: - #{unloaded_gems.map { |gemm| "#{gemm.name} #{gemm.requirement}" } * "\n "} - - You're running: - ruby #{Gem.ruby_version} at #{Gem.ruby} - rubygems #{Gem::RubyGemsVersion} at #{Gem.path * ', '} - - Run `rake gems:install` to install the missing gems. - end_error - end - else - configuration.gems_dependencies_loaded = true - end - end - # # bail out if gems are missing - note that check_gem_dependencies will have # # already called abort() unless $gems_rake_task is set # return unless gems_dependencies_loaded - initializer :load_application_initializers do - if config.gems_dependencies_loaded - Dir["#{configuration.root}/config/initializers/**/*.rb"].sort.each do |initializer| - load(initializer) - end + Dir["#{configuration.root}/config/initializers/**/*.rb"].sort.each do |initializer| + load(initializer) end end # Fires the user-supplied after_initialize block (Configuration#after_initialize) initializer :after_initialize do - if config.gems_dependencies_loaded - configuration.after_initialize_blocks.each do |block| - block.call - end + configuration.after_initialize_blocks.each do |block| + block.call end end @@ -451,7 +385,7 @@ module Rails # # # Observers are loaded after plugins in case Observers or observed models are modified by plugins. initializer :load_observers do - if config.gems_dependencies_loaded && configuration.frameworks.include?(:active_record) + if configuration.frameworks.include?(:active_record) ActiveRecord::Base.instantiate_observers end end @@ -487,5 +421,16 @@ module Rails Rails::Generators.options.deep_merge! config.generators.options end end + + # For each framework, search for instrument file with Notifications hooks. + # + initializer :load_notifications_hooks do + config.frameworks.each do |framework| + begin + require "#{framework}/notifications" + rescue LoadError => e + end + end + end end end diff --git a/railties/lib/rails/backtrace_cleaner.rb b/railties/lib/rails/backtrace_cleaner.rb index 9ff8367807..cd7dd0f80a 100644 --- a/railties/lib/rails/backtrace_cleaner.rb +++ b/railties/lib/rails/backtrace_cleaner.rb @@ -1,5 +1,4 @@ require 'active_support/backtrace_cleaner' -require 'rails/gem_dependency' module Rails class BacktraceCleaner < ActiveSupport::BacktraceCleaner @@ -18,7 +17,7 @@ module Rails def initialize super - add_filter { |line| line.sub("#{RAILS_ROOT}/", '') } + add_filter { |line| line.sub("#{Rails.root}/", '') } add_filter { |line| line.sub(ERB_METHOD_SIG, '') } add_filter { |line| line.sub('./', '/') } # for tests @@ -28,17 +27,14 @@ module Rails add_silencer { |line| RAILS_GEMS.any? { |gem| line =~ /^#{gem} / } } add_silencer { |line| line =~ %r(vendor/plugins/[^\/]+/lib) } end - - + private def add_gem_filters + return unless defined? Gem (Gem.path + [Gem.default_dir]).uniq.each do |path| # http://gist.github.com/30430 add_filter { |line| line.sub(/(#{path})\/gems\/([a-z]+)-([0-9.]+)\/(.*)/, '\2 (\3) \4')} end - - vendor_gems_path = Rails::GemDependency.unpacked_path.sub("#{RAILS_ROOT}/",'') - add_filter { |line| line.sub(/(#{vendor_gems_path})\/([a-z]+)-([0-9.]+)\/(.*)/, '\2 (\3) [v] \4')} end end diff --git a/railties/lib/rails/commands/about.rb b/railties/lib/rails/commands/about.rb index 9a05c47390..d4c30bbeb2 100644 --- a/railties/lib/rails/commands/about.rb +++ b/railties/lib/rails/commands/about.rb @@ -1,4 +1,2 @@ -require "#{RAILS_ROOT}/config/application" -Rails.application.new require 'rails/info' puts Rails::Info diff --git a/railties/lib/rails/commands/console.rb b/railties/lib/rails/commands/console.rb index 31448bdf1a..b977b7162f 100644 --- a/railties/lib/rails/commands/console.rb +++ b/railties/lib/rails/commands/console.rb @@ -12,7 +12,7 @@ OptionParser.new do |opt| end libs = " -r irb/completion" -libs << %( -r "#{RAILS_ROOT}/config/environment") +libs << %( -r "#{Rails.root}/config/environment") libs << " -r rails/console_app" libs << " -r rails/console_sandbox" if options[:sandbox] libs << " -r rails/console_with_helpers" diff --git a/railties/lib/rails/commands/dbconsole.rb b/railties/lib/rails/commands/dbconsole.rb index e6f11a45db..4e699acf6b 100644 --- a/railties/lib/rails/commands/dbconsole.rb +++ b/railties/lib/rails/commands/dbconsole.rb @@ -25,7 +25,7 @@ OptionParser.new do |opt| end env = ARGV.first || ENV['RAILS_ENV'] || 'development' -unless config = YAML::load(ERB.new(IO.read(RAILS_ROOT + "/config/database.yml")).result)[env] +unless config = YAML::load(ERB.new(IO.read(Rails.root + "/config/database.yml")).result)[env] abort "No database is configured for the environment '#{env}'" end diff --git a/railties/lib/rails/commands/destroy.rb b/railties/lib/rails/commands/destroy.rb index 860c03e01e..1270fdd033 100644 --- a/railties/lib/rails/commands/destroy.rb +++ b/railties/lib/rails/commands/destroy.rb @@ -1,5 +1,4 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'generators')) -require "#{RAILS_ROOT}/config/application" if ARGV.size == 0 Rails::Generators.help diff --git a/railties/lib/rails/commands/generate.rb b/railties/lib/rails/commands/generate.rb index cfa6a51d94..d91dcf9788 100755 --- a/railties/lib/rails/commands/generate.rb +++ b/railties/lib/rails/commands/generate.rb @@ -1,5 +1,4 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'generators')) -Rails.application.new if ARGV.size == 0 Rails::Generators.help diff --git a/railties/lib/rails/commands/performance/benchmarker.rb b/railties/lib/rails/commands/performance/benchmarker.rb index 5039c5408c..dfba4bf034 100644 --- a/railties/lib/rails/commands/performance/benchmarker.rb +++ b/railties/lib/rails/commands/performance/benchmarker.rb @@ -12,7 +12,6 @@ end require 'benchmark' include Benchmark -Rails.application.new # Don't include compilation in the benchmark ARGV.each { |expression| eval(expression) } @@ -21,4 +20,4 @@ bm(6) do |x| ARGV.each_with_index do |expression, idx| x.report("##{idx + 1}") { N.times { eval(expression) } } end -end +end diff --git a/railties/lib/rails/commands/performance/profiler.rb b/railties/lib/rails/commands/performance/profiler.rb index 7274e2dfb7..aaa075018c 100644 --- a/railties/lib/rails/commands/performance/profiler.rb +++ b/railties/lib/rails/commands/performance/profiler.rb @@ -3,10 +3,6 @@ if ARGV.empty? exit(1) end -# Keep the expensive require out of the profile. -$stderr.puts 'Loading Rails...' -Rails.application.new # Initialize the application - # Define a method to profile. if ARGV[1] and ARGV[1].to_i > 1 eval "def profile_me() #{ARGV[1]}.times { #{ARGV[0]} } end" diff --git a/railties/lib/rails/commands/runner.rb b/railties/lib/rails/commands/runner.rb index d24f36dd63..0246348c77 100644 --- a/railties/lib/rails/commands/runner.rb +++ b/railties/lib/rails/commands/runner.rb @@ -36,8 +36,6 @@ ARGV.delete(code_or_file) ENV["RAILS_ENV"] = options[:environment] RAILS_ENV.replace(options[:environment]) if defined?(RAILS_ENV) -Rails.application.new - begin if code_or_file.nil? $stderr.puts "Run '#{$0} -h' for help." diff --git a/railties/lib/rails/commands/server.rb b/railties/lib/rails/commands/server.rb index c138cbc9bf..29359e49a4 100644 --- a/railties/lib/rails/commands/server.rb +++ b/railties/lib/rails/commands/server.rb @@ -7,7 +7,7 @@ options = { :Port => 3000, :Host => "0.0.0.0", :environment => (ENV['RAILS_ENV'] || "development").dup, - :config => RAILS_ROOT + "/config.ru", + :config => "#{Rails.root}/config.ru", :detach => false, :debugger => false } @@ -46,7 +46,7 @@ puts "=> Rails #{Rails.version} application starting on http://#{options[:Host]} if options[:detach] Process.daemon - pid = "#{RAILS_ROOT}/tmp/pids/server.pid" + pid = "#{Rails.root}/tmp/pids/server.pid" File.open(pid, 'w'){ |f| f.write(Process.pid) } at_exit { File.delete(pid) if File.exist?(pid) } end diff --git a/railties/lib/rails/configuration.rb b/railties/lib/rails/configuration.rb index 322590f108..0a545f23de 100644 --- a/railties/lib/rails/configuration.rb +++ b/railties/lib/rails/configuration.rb @@ -1,10 +1,11 @@ require 'rails/plugin/loader' require 'rails/plugin/locator' +require 'active_support/ordered_options' module Rails class Configuration attr_accessor :cache_classes, :load_paths, - :load_once_paths, :gems_dependencies_loaded, :after_initialize_blocks, + :load_once_paths, :after_initialize_blocks, :frameworks, :framework_root_path, :root, :plugin_paths, :plugins, :plugin_loader, :plugin_locators, :gems, :loaded_plugins, :reload_plugins, :i18n, :gems, :whiny_nils, :consider_all_requests_local, @@ -23,9 +24,9 @@ module Rails @serve_static_assets = true for framework in frameworks - self.send("#{framework}=", Rails::OrderedOptions.new) + self.send("#{framework}=", ActiveSupport::OrderedOptions.new) end - self.active_support = Rails::OrderedOptions.new + self.active_support = ActiveSupport::OrderedOptions.new end def after_initialize(&blk) @@ -34,37 +35,25 @@ module Rails def root @root ||= begin - if defined?(RAILS_ROOT) - root = RAILS_ROOT - else - call_stack = caller.map { |p| p.split(':').first } - root_path = call_stack.detect { |p| p !~ %r[railties/lib/rails] } - root_path = File.dirname(root_path) - - while root_path && File.directory?(root_path) && !File.exist?("#{root_path}/config.ru") - parent = File.dirname(root_path) - root_path = parent != root_path && parent - end + call_stack = caller.map { |p| p.split(':').first } + root_path = call_stack.detect { |p| p !~ %r[railties/lib/rails] } + root_path = File.dirname(root_path) - Object.class_eval("RAILS_ROOT = ''") - - root = File.exist?("#{root_path}/config.ru") ? root_path : Dir.pwd + while root_path && File.directory?(root_path) && !File.exist?("#{root_path}/config.ru") + parent = File.dirname(root_path) + root_path = parent != root_path && parent end - root = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? - Pathname.new(root).expand_path.to_s : - Pathname.new(root).realpath.to_s + root = File.exist?("#{root_path}/config.ru") ? root_path : Dir.pwd - # TODO: Remove RAILS_ROOT - RAILS_ROOT.replace(root) - root + RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? + Pathname.new(root).expand_path : + Pathname.new(root).realpath end end def root=(root) - Object.class_eval("RAILS_ROOT = ''") unless defined?(RAILS_ROOT) - RAILS_ROOT.replace(root) - @root = root + @root = Pathname.new(root).expand_path end def paths @@ -230,7 +219,7 @@ module Rails def i18n @i18n ||= begin - i18n = Rails::OrderedOptions.new + i18n = ActiveSupport::OrderedOptions.new i18n.load_path = [] if File.exist?(File.join(root, 'config', 'locales')) @@ -242,25 +231,6 @@ module Rails end end - # Adds a single Gem dependency to the rails application. By default, it will require - # the library with the same name as the gem. Use :lib to specify a different name. - # - # # gem 'aws-s3', '>= 0.4.0' - # # require 'aws/s3' - # config.gem 'aws-s3', :lib => 'aws/s3', :version => '>= 0.4.0', \ - # :source => "http://code.whytheluckystiff.net" - # - # To require a library be installed, but not attempt to load it, pass :lib => false - # - # config.gem 'qrp', :version => '0.4.1', :lib => false - def gem(name, options = {}) - gems << Rails::GemDependency.new(name, options) - end - - def gems - @gems ||= [] - end - def environment_path "#{root}/config/environments/#{RAILS_ENV}.rb" end @@ -290,6 +260,14 @@ module Rails end end + # Allows Notifications queue to be modified. + # + # config.notifications.queue = MyNewQueue.new + # + def notifications + ActiveSupport::Notifications + end + class Generators #:nodoc: attr_accessor :aliases, :options, :colorize_logging diff --git a/railties/lib/rails/core.rb b/railties/lib/rails/core.rb index 929c38bd22..a5e51ad04a 100644 --- a/railties/lib/rails/core.rb +++ b/railties/lib/rails/core.rb @@ -6,7 +6,7 @@ module Rails # TODO: w0t? class << self def application - @@application + @@application ||= nil end def application=(application) @@ -18,6 +18,10 @@ module Rails application.configuration end + def initialize! + application.initialize! + end + def initialized? @initialized || false end @@ -43,7 +47,7 @@ module Rails end def root - Pathname.new(RAILS_ROOT) if defined?(RAILS_ROOT) + application && application.config.root end def env @@ -66,36 +70,4 @@ module Rails @@public_path = path end end - - class OrderedOptions < Array #:nodoc: - def []=(key, value) - key = key.to_sym - - if pair = find_pair(key) - pair.pop - pair << value - else - self << [key, value] - end - end - - def [](key) - pair = find_pair(key.to_sym) - pair ? pair.last : nil - end - - def method_missing(name, *args) - if name.to_s =~ /(.*)=$/ - self[$1.to_sym] = args.first - else - self[name] - end - end - - private - def find_pair(key) - self.each { |i| return i if i.first == key } - return false - end - end end
\ No newline at end of file diff --git a/railties/lib/rails/deprecation.rb b/railties/lib/rails/deprecation.rb new file mode 100644 index 0000000000..3c5b8bdec7 --- /dev/null +++ b/railties/lib/rails/deprecation.rb @@ -0,0 +1,25 @@ +require "active_support/string_inquirer" +require "active_support/deprecation" + +RAILS_ROOT = (Class.new(ActiveSupport::Deprecation::DeprecationProxy) do + def target + Rails.root + end + + def replace(val) + puts OMG + end + + def warn(callstack, called, args) + msg = "RAILS_ROOT is deprecated! Use Rails.root instead." + ActiveSupport::Deprecation.warn(msg, callstack) + end +end).new + +module Rails + class Configuration + def gem(*args) + ActiveSupport::Deprecation.warn("config.gem has been deprecated in favor of the Gemfile.") + end + end +end
\ No newline at end of file diff --git a/railties/lib/rails/gem_builder.rb b/railties/lib/rails/gem_builder.rb deleted file mode 100644 index 79c61cc034..0000000000 --- a/railties/lib/rails/gem_builder.rb +++ /dev/null @@ -1,21 +0,0 @@ -require 'rubygems' -require 'rubygems/installer' - -module Rails - - # this class hijacks the functionality of Gem::Installer by overloading its - # initializer to only provide the information needed by - # Gem::Installer#build_extensions (which happens to be what we have) - class GemBuilder < Gem::Installer - - def initialize(spec, gem_dir) - @spec = spec - @gem_dir = gem_dir - end - - # silence the underlying builder - def say(message) - end - - end -end diff --git a/railties/lib/rails/gem_dependency.rb b/railties/lib/rails/gem_dependency.rb deleted file mode 100644 index 06d830ba24..0000000000 --- a/railties/lib/rails/gem_dependency.rb +++ /dev/null @@ -1,311 +0,0 @@ -require 'rails/vendor_gem_source_index' - -module Gem - def self.source_index=(index) - @@source_index = index - end -end - -module Rails - class GemDependency < Gem::Dependency - attr_accessor :lib, :source, :dep - - def self.unpacked_path - @unpacked_path ||= File.join(RAILS_ROOT, 'vendor', 'gems') - end - - @@framework_gems = {} - - def self.add_frozen_gem_path - @@paths_loaded ||= begin - source_index = Rails::VendorGemSourceIndex.new(Gem.source_index) - Gem.clear_paths - Gem.source_index = source_index - # loaded before us - we can't change them, so mark them - Gem.loaded_specs.each do |name, spec| - @@framework_gems[name] = spec - end - true - end - end - - def self.from_directory_name(directory_name, load_spec=true) - directory_name_parts = File.basename(directory_name).split('-') - name = directory_name_parts[0..-2].join('-') - version = directory_name_parts.last - result = self.new(name, :version => version) - spec_filename = File.join(directory_name, '.specification') - if load_spec - raise "Missing specification file in #{File.dirname(spec_filename)}. Perhaps you need to do a 'rake gems:refresh_specs'?" unless File.exists?(spec_filename) - spec = YAML::load_file(spec_filename) - result.specification = spec - end - result - rescue ArgumentError => e - raise "Unable to determine gem name and version from '#{directory_name}'" - end - - def initialize(name, options = {}) - require 'rubygems' unless Object.const_defined?(:Gem) - - if options[:requirement] - req = options[:requirement] - elsif options[:version] - req = Gem::Requirement.create(options[:version]) - else - req = Gem::Requirement.default - end - - @lib = options[:lib] - @source = options[:source] - @loaded = @frozen = @load_paths_added = false - - super(name, req) - end - - def add_load_paths - self.class.add_frozen_gem_path - return if @loaded || @load_paths_added - if framework_gem? - @load_paths_added = @loaded = @frozen = true - return - end - gem self - @spec = Gem.loaded_specs[name] - @frozen = @spec.loaded_from.include?(self.class.unpacked_path) if @spec - @load_paths_added = true - rescue Gem::LoadError - end - - def dependencies - return [] if framework_gem? - return [] unless installed? - specification.dependencies.reject do |dependency| - dependency.type == :development - end.map do |dependency| - GemDependency.new(dependency.name, :requirement => dependency.version_requirements) - end - end - - def specification - # code repeated from Gem.activate. Find a matching spec, or the currently loaded version. - # error out if loaded version and requested version are incompatible. - @spec ||= begin - matches = Gem.source_index.search(self) - matches << @@framework_gems[name] if framework_gem? - if Gem.loaded_specs[name] then - # This gem is already loaded. If the currently loaded gem is not in the - # list of candidate gems, then we have a version conflict. - existing_spec = Gem.loaded_specs[name] - unless matches.any? { |spec| spec.version == existing_spec.version } then - raise Gem::Exception, - "can't activate #{@dep}, already activated #{existing_spec.full_name}" - end - # we're stuck with it, so change to match - version_requirements = Gem::Requirement.create("=#{existing_spec.version}") - existing_spec - else - # new load - matches.last - end - end - end - - def specification=(s) - @spec = s - end - - def requirement - r = version_requirements - (r == Gem::Requirement.default) ? nil : r - end - - def built? - return false unless frozen? - - if vendor_gem? - specification.extensions.each do |ext| - makefile = File.join(unpacked_gem_directory, File.dirname(ext), 'Makefile') - return false unless File.exists?(makefile) - end - end - - true - end - - def framework_gem? - @@framework_gems.has_key?(name) - end - - def frozen? - @frozen ||= vendor_rails? || vendor_gem? - end - - def installed? - Gem.loaded_specs.keys.include?(name) - end - - def load_paths_added? - # always try to add load paths - even if a gem is loaded, it may not - # be a compatible version (ie random_gem 0.4 is loaded and a later spec - # needs >= 0.5 - gem 'random_gem' will catch this and error out) - @load_paths_added - end - - def loaded? - @loaded ||= begin - if vendor_rails? - true - elsif specification.nil? - false - else - # check if the gem is loaded by inspecting $" - # specification.files lists all the files contained in the gem - gem_files = specification.files - # select only the files contained in require_paths - typically in bin and lib - require_paths_regexp = Regexp.new("^(#{specification.require_paths*'|'})/") - gem_lib_files = gem_files.select { |f| require_paths_regexp.match(f) } - # chop the leading directory off - a typical file might be in - # lib/gem_name/file_name.rb, but it will be 'require'd as gem_name/file_name.rb - gem_lib_files.map! { |f| f.split('/', 2)[1] } - # if any of the files from the above list appear in $", the gem is assumed to - # have been loaded - !(gem_lib_files & $").empty? - end - end - end - - def vendor_rails? - Gem.loaded_specs.has_key?(name) && Gem.loaded_specs[name].loaded_from.empty? - end - - def vendor_gem? - specification && File.exists?(unpacked_gem_directory) - end - - def build(options={}) - require 'rails/gem_builder' - return if specification.nil? - if options[:force] || !built? - return unless File.exists?(unpacked_specification_filename) - spec = YAML::load_file(unpacked_specification_filename) - Rails::GemBuilder.new(spec, unpacked_gem_directory).build_extensions - puts "Built gem: '#{unpacked_gem_directory}'" - end - dependencies.each { |dep| dep.build(options) } - end - - def install - unless installed? - cmd = "#{gem_command} #{install_command.join(' ')}" - puts cmd - puts %x(#{cmd}) - end - end - - def load - return if @loaded || @load_paths_added == false - require(@lib || name) unless @lib == false - @loaded = true - rescue LoadError - puts $!.to_s - $!.backtrace.each { |b| puts b } - end - - def refresh - Rails::VendorGemSourceIndex.silence_spec_warnings = true - real_gems = Gem.source_index.installed_source_index - exact_dep = Gem::Dependency.new(name, "= #{specification.version}") - matches = real_gems.search(exact_dep) - installed_spec = matches.first - if frozen? - if installed_spec - # we have a real copy - # get a fresh spec - matches should only have one element - # note that there is no reliable method to check that the loaded - # spec is the same as the copy from real_gems - Gem.activate changes - # some of the fields - real_spec = Gem::Specification.load(matches.first.loaded_from) - write_specification(real_spec) - puts "Reloaded specification for #{name} from installed gems." - else - # the gem isn't installed locally - write out our current specs - write_specification(specification) - puts "Gem #{name} not loaded locally - writing out current spec." - end - else - if framework_gem? - puts "Gem directory for #{name} not found - check if it's loading before rails." - else - puts "Something bad is going on - gem directory not found for #{name}." - end - end - end - - def unpack(options={}) - unless frozen? || framework_gem? - FileUtils.mkdir_p unpack_base - Dir.chdir unpack_base do - Gem::GemRunner.new.run(unpack_command) - end - # Gem.activate changes the spec - get the original - real_spec = Gem::Specification.load(specification.loaded_from) - write_specification(real_spec) - end - dependencies.each { |dep| dep.unpack(options) } if options[:recursive] - end - - def write_specification(spec) - # copy the gem's specification into GEMDIR/.specification so that - # we can access information about the gem on deployment systems - # without having the gem installed - File.open(unpacked_specification_filename, 'w') do |file| - file.puts spec.to_yaml - end - end - - def ==(other) - self.name == other.name && self.requirement == other.requirement - end - alias_method :"eql?", :"==" - - private - - def gem_command - case RUBY_PLATFORM - when /win32/ - 'gem.bat' - when /java/ - 'jruby -S gem' - else - 'gem' - end - end - - def install_command - cmd = %w(install) << name - cmd << "--version" << %("#{requirement.to_s}") if requirement - cmd << "--source" << @source if @source - cmd - end - - def unpack_command - cmd = %w(unpack) << name - cmd << "--version" << "= "+specification.version.to_s if requirement - cmd - end - - def unpack_base - Rails::GemDependency.unpacked_path - end - - def unpacked_gem_directory - File.join(unpack_base, specification.full_name) - end - - def unpacked_specification_filename - File.join(unpacked_gem_directory, '.specification') - end - - end -end diff --git a/railties/lib/rails/generators.rb b/railties/lib/rails/generators.rb index 471eb45ee6..49f32aa0db 100644 --- a/railties/lib/rails/generators.rb +++ b/railties/lib/rails/generators.rb @@ -9,7 +9,7 @@ require 'active_support/core_ext/module/attribute_accessors' require 'active_support/core_ext/string/inflections' # TODO: Do not always push on vendored thor -$LOAD_PATH.unshift("#{File.dirname(__FILE__)}/vendor/thor-0.11.6/lib") +$LOAD_PATH.unshift("#{File.dirname(__FILE__)}/vendor/thor-0.11.8/lib") require 'rails/generators/base' require 'rails/generators/named_base' @@ -92,8 +92,6 @@ module Rails generator_path = File.join(spec.full_gem_path, "lib/generators") paths << generator_path if File.exist?(generator_path) end - elsif defined?(RAILS_ROOT) - paths += Dir[File.join(RAILS_ROOT, "vendor", "gems", "gems", "*", "lib", "generators")] end paths @@ -102,8 +100,8 @@ module Rails # Load paths from plugin. # def self.plugins_generators_paths - return [] unless defined?(RAILS_ROOT) - Dir[File.join(RAILS_ROOT, "vendor", "plugins", "*", "lib", "generators")] + return [] unless Rails.root + Dir[File.join(Rails.root, "vendor", "plugins", "*", "lib", "generators")] end # Hold configured generators fallbacks. If a plugin developer wants a @@ -143,7 +141,7 @@ module Rails def self.load_paths @load_paths ||= begin paths = [] - paths << File.join(RAILS_ROOT, "lib", "generators") if defined?(RAILS_ROOT) + paths << File.join(Rails.root, "lib", "generators") if Rails.root paths << File.join(Thor::Util.user_home, ".rails", "generators") paths += self.plugins_generators_paths paths += self.gems_generators_paths diff --git a/railties/lib/rails/generators/active_model.rb b/railties/lib/rails/generators/active_model.rb index 1a849a0e02..fe6321af30 100644 --- a/railties/lib/rails/generators/active_model.rb +++ b/railties/lib/rails/generators/active_model.rb @@ -32,7 +32,7 @@ module Rails # GET index def self.all(klass) - raise NotImplementedError + "#{klass}.all" end # GET show @@ -40,34 +40,38 @@ module Rails # PUT update # DELETE destroy def self.find(klass, params=nil) - raise NotImplementedError + "#{klass}.find(#{params})" end # GET new # POST create def self.build(klass, params=nil) - raise NotImplementedError + if params + "#{klass}.new(#{params})" + else + "#{klass}.new" + end end # POST create def save - raise NotImplementedError + "#{name}.save" end # PUT update def update_attributes(params=nil) - raise NotImplementedError + "#{name}.update_attributes(#{params})" end # POST create # PUT update def errors - raise NotImplementedError + "#{name}.errors" end # DELETE destroy def destroy - raise NotImplementedError + "#{name}.destroy" end end end diff --git a/railties/lib/rails/generators/active_record.rb b/railties/lib/rails/generators/active_record.rb index c03ea59c1b..babad33db3 100644 --- a/railties/lib/rails/generators/active_record.rb +++ b/railties/lib/rails/generators/active_record.rb @@ -18,39 +18,5 @@ module ActiveRecord end end end - - class ActiveModel < Rails::Generators::ActiveModel #:nodoc: - def self.all(klass) - "#{klass}.all" - end - - def self.find(klass, params=nil) - "#{klass}.find(#{params})" - end - - def self.build(klass, params=nil) - if params - "#{klass}.new(#{params})" - else - "#{klass}.new" - end - end - - def save - "#{name}.save" - end - - def update_attributes(params=nil) - "#{name}.update_attributes(#{params})" - end - - def errors - "#{name}.errors" - end - - def destroy - "#{name}.destroy" - end - end end end diff --git a/railties/lib/rails/generators/base.rb b/railties/lib/rails/generators/base.rb index 720caa5b3f..7af99797ea 100644 --- a/railties/lib/rails/generators/base.rb +++ b/railties/lib/rails/generators/base.rb @@ -203,8 +203,8 @@ module Rails super base.source_root # Cache source root - if defined?(RAILS_ROOT) && base.name !~ /Base$/ - path = File.expand_path(File.join(RAILS_ROOT, 'lib', 'templates')) + if Rails.root && base.name !~ /Base$/ + path = File.expand_path(File.join(Rails.root, 'lib', 'templates')) if base.name.include?('::') base.source_paths << File.join(path, base.base_name, base.generator_name) else diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index 49b13cae2b..93d9ac553d 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -1,4 +1,4 @@ -require 'digest/md5' +require 'digest/md5' require 'active_support/secure_random' require 'rails/version' unless defined?(Rails::VERSION) diff --git a/railties/lib/rails/generators/rails/app/templates/Gemfile b/railties/lib/rails/generators/rails/app/templates/Gemfile index bcbaa432b7..3966c0f70d 100644 --- a/railties/lib/rails/generators/rails/app/templates/Gemfile +++ b/railties/lib/rails/generators/rails/app/templates/Gemfile @@ -1,10 +1,21 @@ # Gemfile is where you list all of your application's dependencies # -gem "rails", "<%= Rails::VERSION::STRING %>" +<%= "# " if options.freeze? %>gem "rails", "<%= Rails::VERSION::STRING %>" # # Bundling edge rails: -# gem "rails", "<%= Rails::VERSION::STRING %>", :git => "git://github.com/rails/rails.git" +<%= "# " unless options.freeze? %>gem "rails", "<%= Rails::VERSION::STRING %>", :git => "git://github.com/rails/rails.git" -# You can list more dependencies here -# gem "nokogiri" -# gem "merb" # ;)
\ No newline at end of file +# Specify gemcutter as a gem source +# source "http://gemcutter.org" + +# Specify gems that this application depends on and have them installed with rake gems:install +# gem "bj" +# gem "hpricot", "0.6" +# gem "sqlite3-ruby", :require_as => "sqlite3" +# gem "aws-s3", :require_as => "aws/s3" + +# Specify gems that should only be required in certain environments +# gem "rspec", :only => :test +# only :test do +# gem "webrat" +# end diff --git a/railties/lib/rails/generators/rails/app/templates/Rakefile b/railties/lib/rails/generators/rails/app/templates/Rakefile index 1dce9863f2..6b6d07e8cc 100755 --- a/railties/lib/rails/generators/rails/app/templates/Rakefile +++ b/railties/lib/rails/generators/rails/app/templates/Rakefile @@ -1,7 +1,7 @@ # Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. -require File.expand_path(File.join(File.dirname(__FILE__), 'config', 'environment')) +require File.expand_path('../config/application', __FILE__) require 'rake' require 'rake/testtask' diff --git a/railties/lib/rails/generators/rails/app/templates/config.ru b/railties/lib/rails/generators/rails/app/templates/config.ru index 3702ad0466..509a0da5b7 100644 --- a/railties/lib/rails/generators/rails/app/templates/config.ru +++ b/railties/lib/rails/generators/rails/app/templates/config.ru @@ -1,5 +1,5 @@ # Require your environment file to bootstrap Rails -require File.expand_path('../config/application', __FILE__) +require ::File.expand_path('../config/environment', __FILE__) # Dispatch the request -run Rails.application.new +run Rails.application diff --git a/railties/lib/rails/generators/rails/app/templates/config/application.rb b/railties/lib/rails/generators/rails/app/templates/config/application.rb index bff74a7786..8008c6ba07 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/application.rb +++ b/railties/lib/rails/generators/rails/app/templates/config/application.rb @@ -1,5 +1,4 @@ -# Bootstrap the Rails environment, frameworks, and default configuration -require File.expand_path(File.join(File.dirname(__FILE__), 'boot')) +require File.expand_path('../boot', __FILE__) Rails::Initializer.run do |config| # Settings in config/environments/* take precedence over those specified here. @@ -7,13 +6,7 @@ Rails::Initializer.run do |config| # -- all .rb files in that directory are automatically loaded. # Add additional load paths for your own custom dirs - # config.load_paths += %W( #{RAILS_ROOT}/extras ) - - # Specify gems that this application depends on and have them installed with rake gems:install - # config.gem "bj" - # config.gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net" - # config.gem "sqlite3-ruby", :lib => "sqlite3" - # config.gem "aws-s3", :lib => "aws/s3" + # config.load_paths += %W( #{root}/extras ) # Only load the plugins named here, in the order given (default is alphabetical). # :all can be used as a placeholder for all plugins not explicitly named @@ -45,4 +38,4 @@ Rails::Initializer.run do |config| # g.template_engine :erb # g.test_framework :test_unit, :fixture => true # end -end
\ No newline at end of file +end diff --git a/railties/lib/rails/generators/rails/app/templates/config/boot.rb b/railties/lib/rails/generators/rails/app/templates/config/boot.rb index 6e0e2279cd..5aa49ca5e6 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/boot.rb +++ b/railties/lib/rails/generators/rails/app/templates/config/boot.rb @@ -1,148 +1,16 @@ -# Don't change this file! -# Configure your app in config/environment.rb and config/environments/*.rb - -RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT) - -module Rails - # Mark the version of Rails that generated the boot.rb file. This is - # a temporary solution and will most likely be removed as Rails 3.0 - # comes closer. - BOOTSTRAP_VERSION = "3.0" - - class << self - def boot! - unless booted? - preinitialize - pick_boot.run - end - end - - def booted? - defined? Rails::Initializer - end - - def pick_boot - (vendor_rails? ? VendorBoot : GemBoot).new - end - - def vendor_rails? - File.exist?("#{RAILS_ROOT}/vendor/rails") - end - - def preinitialize - load(preinitializer_path) if File.exist?(preinitializer_path) - end - - def preinitializer_path - "#{RAILS_ROOT}/config/preinitializer.rb" - end - end - - class Boot - def run - set_load_paths - load_initializer - end - - def set_load_paths - %w( - actionmailer/lib - actionpack/lib - activemodel/lib - activerecord/lib - activeresource/lib - activesupport/lib - railties/lib - railties - ).reverse_each do |path| - path = "#{framework_root_path}/#{path}" - $LOAD_PATH.unshift(path) if File.directory?(path) - $LOAD_PATH.uniq! - end - end - - def framework_root_path - defined?(::RAILS_FRAMEWORK_ROOT) ? ::RAILS_FRAMEWORK_ROOT : "#{RAILS_ROOT}/vendor/rails" - end +# Use Bundler (preferred) +environment = File.expand_path('../../vendor/gems/environment', __FILE__) +if File.exist?("#{environment}.rb") + require environment + +# Use 2.x style vendor/rails and RubyGems +else + vendor_rails = File.expand_path('../../vendor/rails', __FILE__) + if File.exist?(vendor_rails) + Dir["#{vendor_rails}/*/lib"].each { |path| $:.unshift(path) } end - class VendorBoot < Boot - def load_initializer - require "rails" - install_gem_spec_stubs - Rails::GemDependency.add_frozen_gem_path - end - - def install_gem_spec_stubs - begin; require "rubygems"; rescue LoadError; return; end - - %w(rails activesupport activerecord actionpack actionmailer activeresource).each do |stub| - Gem.loaded_specs[stub] ||= Gem::Specification.new do |s| - s.name = stub - s.version = Rails::VERSION::STRING - s.loaded_from = "" - end - end - end - end - - class GemBoot < Boot - def load_initializer - self.class.load_rubygems - load_rails_gem - require 'rails' - end - - def load_rails_gem - if version = self.class.gem_version - gem 'rails', version - else - gem 'rails' - end - rescue Gem::LoadError => load_error - $stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.) - exit 1 - end - - class << self - def rubygems_version - Gem::RubyGemsVersion rescue nil - end - - def gem_version - if defined? RAILS_GEM_VERSION - RAILS_GEM_VERSION - elsif ENV.include?('RAILS_GEM_VERSION') - ENV['RAILS_GEM_VERSION'] - else - parse_gem_version(read_environment_rb) - end - end - - def load_rubygems - min_version = '1.3.2' - require 'rubygems' - unless rubygems_version >= min_version - $stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.) - exit 1 - end - - rescue LoadError - $stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org) - exit 1 - end - - def parse_gem_version(text) - $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/ - end - - private - def read_environment_rb - File.read("#{RAILS_ROOT}/config/environment.rb") - end - end - end + require 'rubygems' end -# All that for this: -Rails.boot! +require 'rails' diff --git a/railties/lib/rails/generators/rails/app/templates/config/environment.rb b/railties/lib/rails/generators/rails/app/templates/config/environment.rb index fcf4eddb00..0bb191f205 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/environment.rb +++ b/railties/lib/rails/generators/rails/app/templates/config/environment.rb @@ -1,9 +1,5 @@ -# Be sure to restart your server when you modify this file - -# Specifies gem version of Rails to use when vendor/rails is not present -<%= '# ' if options[:freeze] %>RAILS_GEM_VERSION = '<%= Rails::VERSION::STRING %>' unless defined? RAILS_GEM_VERSION - # Load the rails application -require File.expand_path(File.join(File.dirname(__FILE__), 'application')) +require File.expand_path('../application', __FILE__) + # Initialize the rails application -Rails.application.new +Rails.initialize! diff --git a/railties/lib/rails/generators/rails/app/templates/script/about.tt b/railties/lib/rails/generators/rails/app/templates/script/about.tt index 90a320297e..7639d4040f 100755 --- a/railties/lib/rails/generators/rails/app/templates/script/about.tt +++ b/railties/lib/rails/generators/rails/app/templates/script/about.tt @@ -1,4 +1,4 @@ <%= shebang %> -require File.expand_path('../../config/application', __FILE__) +require File.expand_path('../../config/environment', __FILE__) $LOAD_PATH.unshift "#{RAILTIES_PATH}/builtin/rails_info" require 'rails/commands/about' diff --git a/railties/lib/rails/generators/rails/app/templates/script/generate.tt b/railties/lib/rails/generators/rails/app/templates/script/generate.tt index 2a9d219531..26f029c6a6 100755 --- a/railties/lib/rails/generators/rails/app/templates/script/generate.tt +++ b/railties/lib/rails/generators/rails/app/templates/script/generate.tt @@ -1,3 +1,3 @@ <%= shebang %> -require File.expand_path('../../config/application', __FILE__) +require File.expand_path('../../config/environment', __FILE__) require 'rails/commands/generate' diff --git a/railties/lib/rails/generators/rails/app/templates/script/performance/benchmarker.tt b/railties/lib/rails/generators/rails/app/templates/script/performance/benchmarker.tt index 90aca9b4e9..9ebc4c92fc 100755 --- a/railties/lib/rails/generators/rails/app/templates/script/performance/benchmarker.tt +++ b/railties/lib/rails/generators/rails/app/templates/script/performance/benchmarker.tt @@ -1,3 +1,3 @@ <%= shebang %> -require File.expand_path('../../../config/application', __FILE__) +require File.expand_path('../../../config/environment', __FILE__) require 'rails/commands/performance/benchmarker' diff --git a/railties/lib/rails/generators/rails/app/templates/script/performance/profiler.tt b/railties/lib/rails/generators/rails/app/templates/script/performance/profiler.tt index 39569b4e70..5f4c763f9d 100755 --- a/railties/lib/rails/generators/rails/app/templates/script/performance/profiler.tt +++ b/railties/lib/rails/generators/rails/app/templates/script/performance/profiler.tt @@ -1,3 +1,3 @@ <%= shebang %> -require File.expand_path('../../../config/application', __FILE__) +require File.expand_path('../../../config/environment', __FILE__) require 'rails/commands/performance/profiler' diff --git a/railties/lib/rails/generators/rails/app/templates/script/runner.tt b/railties/lib/rails/generators/rails/app/templates/script/runner.tt index 872ec07a1e..34ad7c18eb 100755 --- a/railties/lib/rails/generators/rails/app/templates/script/runner.tt +++ b/railties/lib/rails/generators/rails/app/templates/script/runner.tt @@ -1,3 +1,3 @@ <%= shebang %> -require File.expand_path('../../config/application', __FILE__) +require File.expand_path('../../config/environment', __FILE__) require 'rails/commands/runner' diff --git a/railties/lib/rails/generators/resource_helpers.rb b/railties/lib/rails/generators/resource_helpers.rb index d4b0d4b945..0385581083 100644 --- a/railties/lib/rails/generators/resource_helpers.rb +++ b/railties/lib/rails/generators/resource_helpers.rb @@ -1,3 +1,5 @@ +require 'rails/generators/active_model' + module Rails module Generators # Deal with controller names on scaffold and add some helpers to deal with @@ -47,20 +49,11 @@ module Rails raise "You need to have :orm as class option to invoke orm_class and orm_instance" end - active_model = "#{options[:orm].to_s.classify}::Generators::ActiveModel" - - # If the orm was not loaded, try to load it at "generators/orm", - # for example "generators/active_record" or "generators/sequel". begin - klass = active_model.constantize - rescue NameError - require "rails/generators/#{options[:orm]}" + "#{options[:orm].to_s.classify}::Generators::ActiveModel".constantize + rescue NameError => e + Rails::Generators::ActiveModel end - - # Try once again after loading the file with success. - klass ||= active_model.constantize - rescue Exception => e - raise Error, "Could not load #{active_model}, skipping controller. Error: #{e.message}." end end diff --git a/railties/lib/rails/initializable.rb b/railties/lib/rails/initializable.rb index 4bd5088207..c491d5e012 100644 --- a/railties/lib/rails/initializable.rb +++ b/railties/lib/rails/initializable.rb @@ -1,78 +1,86 @@ module Rails module Initializable - - # A collection of initializers - class Collection - def initialize(context) - @context = context - @keys = [] - @values = {} - @ran = false + def self.included(klass) + klass.instance_eval do + extend Rails::Initializable + extend Rails::Initializable::ClassMethodsWhenIncluded + include Rails::Initializable::InstanceMethodsWhenIncluded end + end - def run - return self if @ran - each do |key, initializer| - @context.class_eval(&initializer.block) - end - @ran = true - self - end + def self.extended(klass) + klass.extend Initializer + end - def [](key) - keys, values = merge_with_parent - values[key.to_sym] + class Collection < Array + def initialize(klasses) + klasses.each do |klass| + (klass.added_initializers || []).each do |initializer| + index = if initializer.before + index_for(initializer.before) + elsif initializer.after + index_for(initializer.after) + 1 + else + length + end + + insert(index, initializer) + end + end end - def []=(key, value) - key = key.to_sym - @keys |= [key] - @values[key] = value + def index_for(name) + inst = find {|i| i.name == name } + inst && index(inst) end - def each - keys, values = merge_with_parent - keys.each { |k| yield k, values[k] } - self - end + end - protected + attr_reader :added_initializers - attr_reader :keys, :values + # When you include Rails::Initializable, this method will be on instances + # of the class included into. When you extend it, it will be on the + # class or module itself. + # + # The #initializers method is set up to return the right list of + # initializers for the context in question. + def run_initializers + return if @_initialized - private + initializers.each {|initializer| instance_eval(&initializer.block) } - def merge_with_parent - keys, values = [], {} + @_initialized = true + end - if @context.is_a?(Class) && @context.superclass.is_a?(Initializable) - parent = @context.superclass.initializers - keys, values = parent.keys, parent.values - end + module Initializer + Initializer = Struct.new(:name, :before, :after, :block, :global) - values = values.merge(@values) - return keys | @keys, values + def all_initializers + klasses = ancestors.select {|klass| klass.is_a?(Initializable) }.reverse + initializers = Collection.new(klasses) end - end - - class Initializer - attr_reader :name, :options, :block + alias initializers all_initializers - def initialize(name, options = {}, &block) - @name, @options, @block = name, options, block + def initializer(name, options = {}, &block) + @added_initializers ||= [] + @added_initializers << + Initializer.new(name, options[:before], options[:after], block, options[:global]) end end - def initializer(name, options = {}, &block) - @initializers ||= Collection.new(self) - @initializers[name] = Initializer.new(name, options, &block) - end + module ClassMethodsWhenIncluded + def initializers + all_initializers.select {|i| i.global == true } + end - def initializers - @initializers ||= Collection.new(self) end + module InstanceMethodsWhenIncluded + def initializers + self.class.all_initializers.reject {|i| i.global == true } + end + end end extend Initializable diff --git a/railties/lib/rails/initializer.rb b/railties/lib/rails/initializer.rb index bb86f70da6..2ad1e52746 100644 --- a/railties/lib/rails/initializer.rb +++ b/railties/lib/rails/initializer.rb @@ -4,11 +4,11 @@ require 'rails/initializable' require 'rails/application' require 'rails/railties_path' require 'rails/version' -require 'rails/gem_dependency' require 'rails/rack' require 'rails/paths' require 'rails/core' require 'rails/configuration' +require 'rails/deprecation' RAILS_ENV = (ENV['RAILS_ENV'] || 'development').dup unless defined?(RAILS_ENV) diff --git a/railties/lib/rails/plugin/loader.rb b/railties/lib/rails/plugin/loader.rb index 0d16cbd7c3..4808c6ad57 100644 --- a/railties/lib/rails/plugin/loader.rb +++ b/railties/lib/rails/plugin/loader.rb @@ -147,7 +147,7 @@ module Rails end def application_lib_index - $LOAD_PATH.index(File.join(RAILS_ROOT, 'lib')) || 0 + $LOAD_PATH.index(File.join(Rails.root, 'lib')) || 0 end def enabled?(plugin) diff --git a/railties/lib/rails/plugin/locator.rb b/railties/lib/rails/plugin/locator.rb index 1057c004e0..56cbaf37c6 100644 --- a/railties/lib/rails/plugin/locator.rb +++ b/railties/lib/rails/plugin/locator.rb @@ -78,7 +78,7 @@ module Rails # a <tt>rails/init.rb</tt> file. class GemLocator < Locator def plugins - gem_index = initializer.configuration.gems.inject({}) { |memo, gem| memo.update gem.specification => gem } + gem_index = {} specs = gem_index.keys specs += Gem.loaded_specs.values.select do |spec| spec.loaded_from && # prune stubs diff --git a/railties/lib/rails/tasks.rb b/railties/lib/rails/tasks.rb index aad965306c..82113a297c 100644 --- a/railties/lib/rails/tasks.rb +++ b/railties/lib/rails/tasks.rb @@ -6,7 +6,6 @@ $VERBOSE = nil databases documentation framework - gems log middleware misc @@ -20,5 +19,5 @@ end # Load any custom rakefile extensions # TODO: Don't hardcode these paths. -Dir["#{RAILS_ROOT}/vendor/plugins/*/**/tasks/**/*.rake"].sort.each { |ext| load ext } -Dir["#{RAILS_ROOT}/lib/tasks/**/*.rake"].sort.each { |ext| load ext } +Dir["#{Rails.root}/vendor/plugins/*/**/tasks/**/*.rake"].sort.each { |ext| load ext } +Dir["#{Rails.root}/lib/tasks/**/*.rake"].sort.each { |ext| load ext } diff --git a/railties/lib/rails/tasks/databases.rake b/railties/lib/rails/tasks/databases.rake index ed015e7a67..a35a6c156b 100644 --- a/railties/lib/rails/tasks/databases.rake +++ b/railties/lib/rails/tasks/databases.rake @@ -283,7 +283,7 @@ namespace :db do desc "Create a db/schema.rb file that can be portably used against any DB supported by AR" task :dump => :environment do require 'active_record/schema_dumper' - File.open(ENV['SCHEMA'] || "#{RAILS_ROOT}/db/schema.rb", "w") do |file| + File.open(ENV['SCHEMA'] || "#{Rails.root}/db/schema.rb", "w") do |file| ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file) end Rake::Task["db:schema:dump"].reenable @@ -291,11 +291,11 @@ namespace :db do desc "Load a schema.rb file into the database" task :load => :environment do - file = ENV['SCHEMA'] || "#{RAILS_ROOT}/db/schema.rb" + file = ENV['SCHEMA'] || "#{Rails.root}/db/schema.rb" if File.exists?(file) load(file) else - abort %{#{file} doesn't exist yet. Run "rake db:migrate" to create it then try again. If you do not intend to use a database, you should instead alter #{RAILS_ROOT}/config/environment.rb to prevent active_record from loading: config.frameworks -= [ :active_record ]} + abort %{#{file} doesn't exist yet. Run "rake db:migrate" to create it then try again. If you do not intend to use a database, you should instead alter #{Rails.root}/config/application.rb to prevent active_record from loading: config.frameworks -= [ :active_record ]} end end end @@ -307,7 +307,7 @@ namespace :db do case abcs[RAILS_ENV]["adapter"] when "mysql", "oci", "oracle" ActiveRecord::Base.establish_connection(abcs[RAILS_ENV]) - File.open("#{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql", "w+") { |f| f << ActiveRecord::Base.connection.structure_dump } + File.open("#{Rails.root}/db/#{RAILS_ENV}_structure.sql", "w+") { |f| f << ActiveRecord::Base.connection.structure_dump } when "postgresql" ENV['PGHOST'] = abcs[RAILS_ENV]["host"] if abcs[RAILS_ENV]["host"] ENV['PGPORT'] = abcs[RAILS_ENV]["port"].to_s if abcs[RAILS_ENV]["port"] @@ -327,13 +327,13 @@ namespace :db do when "firebird" set_firebird_env(abcs[RAILS_ENV]) db_string = firebird_db_string(abcs[RAILS_ENV]) - sh "isql -a #{db_string} > #{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql" + sh "isql -a #{db_string} > #{Rails.root}/db/#{RAILS_ENV}_structure.sql" else raise "Task not supported by '#{abcs["test"]["adapter"]}'" end if ActiveRecord::Base.connection.supports_migrations? - File.open("#{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql", "a") { |f| f << ActiveRecord::Base.connection.dump_schema_information } + File.open("#{Rails.root}/db/#{RAILS_ENV}_structure.sql", "a") { |f| f << ActiveRecord::Base.connection.dump_schema_information } end end end @@ -356,28 +356,28 @@ namespace :db do when "mysql" ActiveRecord::Base.establish_connection(:test) ActiveRecord::Base.connection.execute('SET foreign_key_checks = 0') - IO.readlines("#{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql").join.split("\n\n").each do |table| + IO.readlines("#{Rails.root}/db/#{RAILS_ENV}_structure.sql").join.split("\n\n").each do |table| ActiveRecord::Base.connection.execute(table) end 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"] - `psql -U "#{abcs["test"]["username"]}" -f #{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql #{abcs["test"]["database"]}` + `psql -U "#{abcs["test"]["username"]}" -f #{Rails.root}/db/#{RAILS_ENV}_structure.sql #{abcs["test"]["database"]}` when "sqlite", "sqlite3" dbfile = abcs["test"]["database"] || abcs["test"]["dbfile"] - `#{abcs["test"]["adapter"]} #{dbfile} < #{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql` + `#{abcs["test"]["adapter"]} #{dbfile} < #{Rails.root}/db/#{RAILS_ENV}_structure.sql` when "sqlserver" `osql -E -S #{abcs["test"]["host"]} -d #{abcs["test"]["database"]} -i db\\#{RAILS_ENV}_structure.sql` when "oci", "oracle" ActiveRecord::Base.establish_connection(:test) - IO.readlines("#{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql").join.split(";\n\n").each do |ddl| + IO.readlines("#{Rails.root}/db/#{RAILS_ENV}_structure.sql").join.split(";\n\n").each do |ddl| ActiveRecord::Base.connection.execute(ddl) end when "firebird" set_firebird_env(abcs["test"]) db_string = firebird_db_string(abcs["test"]) - sh "isql -i #{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql #{db_string}" + sh "isql -i #{Rails.root}/db/#{RAILS_ENV}_structure.sql #{db_string}" else raise "Task not supported by '#{abcs["test"]["adapter"]}'" end @@ -446,7 +446,7 @@ def drop_database(config) when /^sqlite/ require 'pathname' path = Pathname.new(config['database']) - file = path.absolute? ? path.to_s : File.join(RAILS_ROOT, path) + file = path.absolute? ? path.to_s : File.join(Rails.root, path) FileUtils.rm(file) when 'postgresql' diff --git a/railties/lib/rails/tasks/framework.rake b/railties/lib/rails/tasks/framework.rake index 16dd0af44e..1611d1d94d 100644 --- a/railties/lib/rails/tasks/framework.rake +++ b/railties/lib/rails/tasks/framework.rake @@ -86,7 +86,7 @@ namespace :rails do template = File.expand_path(template) if template !~ %r{\A[A-Za-z][A-Za-z0-9+\-\.]*://} require 'generators' - generator = Rails::Generators::App.new [ RAILS_ROOT ], {}, :destination_root => RAILS_ROOT + generator = Rails::Generators::App.new [ Rails.root ], {}, :destination_root => Rails.root generator.apply template, :verbose => false end @@ -96,15 +96,10 @@ namespace :rails do require 'rails/generators/rails/app/app_generator' generator = Rails::Generators::AppGenerator.new ["rails"], { :with_dispatchers => true }, - :destination_root => RAILS_ROOT + :destination_root => Rails.root generator.invoke(method) end - desc "Update config/boot.rb from your current rails install" - task :configs do - invoke_from_app_generator :create_boot_file - end - desc "Update Prototype javascripts from your current rails install" task :javascripts do invoke_from_app_generator :create_prototype_files @@ -117,8 +112,8 @@ namespace :rails do desc "Rename application.rb to application_controller.rb" task :application_controller do - old_style = RAILS_ROOT + '/app/controllers/application.rb' - new_style = RAILS_ROOT + '/app/controllers/application_controller.rb' + old_style = Rails.root + '/app/controllers/application.rb' + new_style = Rails.root + '/app/controllers/application_controller.rb' if File.exists?(old_style) && !File.exists?(new_style) FileUtils.mv(old_style, new_style) puts "#{old_style} has been renamed to #{new_style}, update your SCM as necessary" diff --git a/railties/lib/rails/tasks/gems.rake b/railties/lib/rails/tasks/gems.rake deleted file mode 100644 index f1c34c7cca..0000000000 --- a/railties/lib/rails/tasks/gems.rake +++ /dev/null @@ -1,78 +0,0 @@ -desc "List the gems that this rails application depends on" -task :gems => 'gems:base' do - Rails.configuration.gems.each do |gem| - print_gem_status(gem) - end - puts - puts "I = Installed" - puts "F = Frozen" - puts "R = Framework (loaded before rails starts)" -end - -namespace :gems do - task :base do - $gems_rake_task = true - require 'rubygems' - require 'rubygems/gem_runner' - Rake::Task[:environment].invoke - end - - desc "Build any native extensions for unpacked gems" - task :build do - $gems_build_rake_task = true - frozen_gems.each { |gem| gem.build } - end - - namespace :build do - desc "Force the build of all gems" - task :force do - $gems_build_rake_task = true - frozen_gems.each { |gem| gem.build(:force => true) } - end - end - - desc "Installs all required gems." - task :install => :base do - current_gems.each { |gem| gem.install } - end - - desc "Unpacks all required gems into vendor/gems." - task :unpack => :install do - current_gems.each { |gem| gem.unpack } - end - - namespace :unpack do - desc "Unpacks all required gems and their dependencies into vendor/gems." - task :dependencies => :install do - current_gems.each { |gem| gem.unpack(:recursive => true) } - end - end - - desc "Regenerate gem specifications in correct format." - task :refresh_specs do - frozen_gems(false).each { |gem| gem.refresh } - end -end - -def current_gems - gems = Rails.configuration.gems - gems = gems.select { |gem| gem.name == ENV['GEM'] } unless ENV['GEM'].blank? - gems -end - -def frozen_gems(load_specs=true) - Dir[File.join(RAILS_ROOT, 'vendor', 'gems', '*-*')].map do |gem_dir| - Rails::GemDependency.from_directory_name(gem_dir, load_specs) - end -end - -def print_gem_status(gem, indent=1) - code = case - when gem.framework_gem? then 'R' - when gem.frozen? then 'F' - when gem.installed? then 'I' - else ' ' - end - puts " "*(indent-1)+" - [#{code}] #{gem.name} #{gem.requirement.to_s}" - gem.dependencies.each { |g| print_gem_status(g, indent+1) } -end diff --git a/railties/lib/rails/tasks/misc.rake b/railties/lib/rails/tasks/misc.rake index fb2fc31dc1..7f244ebaed 100644 --- a/railties/lib/rails/tasks/misc.rake +++ b/railties/lib/rails/tasks/misc.rake @@ -1,7 +1,7 @@ task :default => :test task :environment do $rails_rake_task = true - require(File.join(RAILS_ROOT, 'config', 'environment')) + require(File.join(Rails.root, 'config', 'environment')) end task :rails_env do diff --git a/railties/lib/rails/tasks/routes.rake b/railties/lib/rails/tasks/routes.rake index abbf3258c1..2395d73b2f 100644 --- a/railties/lib/rails/tasks/routes.rake +++ b/railties/lib/rails/tasks/routes.rake @@ -3,16 +3,13 @@ task :routes => :environment do all_routes = ENV['CONTROLLER'] ? ActionController::Routing::Routes.routes.select { |route| route.defaults[:controller] == ENV['CONTROLLER'] } : ActionController::Routing::Routes.routes routes = all_routes.collect do |route| name = ActionController::Routing::Routes.named_routes.routes.index(route).to_s - verb = route.conditions[:method].to_s.upcase - segs = route.segments.inject("") { |str,s| str << s.to_s } - segs.chop! if segs.length > 1 reqs = route.requirements.empty? ? "" : route.requirements.inspect - {:name => name, :verb => verb, :segs => segs, :reqs => reqs} + {:name => name, :verb => route.verb.to_s, :path => route.path, :reqs => reqs} end name_width = routes.collect {|r| r[:name]}.collect {|n| n.length}.max verb_width = routes.collect {|r| r[:verb]}.collect {|v| v.length}.max - segs_width = routes.collect {|r| r[:segs]}.collect {|s| s.length}.max + path_width = routes.collect {|r| r[:path]}.collect {|s| s.length}.max routes.each do |r| - puts "#{r[:name].rjust(name_width)} #{r[:verb].ljust(verb_width)} #{r[:segs].ljust(segs_width)} #{r[:reqs]}" + puts "#{r[:name].rjust(name_width)} #{r[:verb].ljust(verb_width)} #{r[:path].ljust(path_width)} #{r[:reqs]}" end end diff --git a/railties/lib/rails/tasks/statistics.rake b/railties/lib/rails/tasks/statistics.rake index 2dcc7bdf9d..40f8c1034a 100644 --- a/railties/lib/rails/tasks/statistics.rake +++ b/railties/lib/rails/tasks/statistics.rake @@ -1,14 +1,13 @@ STATS_DIRECTORIES = [ %w(Controllers app/controllers), - %w(Helpers app/helpers), + %w(Helpers app/helpers), %w(Models app/models), %w(Libraries lib/), %w(APIs app/apis), %w(Integration\ tests test/integration), %w(Functional\ tests test/functional), %w(Unit\ tests test/unit) - -].collect { |name, dir| [ name, "#{RAILS_ROOT}/#{dir}" ] }.select { |name, dir| File.directory?(dir) } +].collect { |name, dir| [ name, "#{Rails.root}/#{dir}" ] }.select { |name, dir| File.directory?(dir) } desc "Report code statistics (KLOCs, etc) from the application" task :stats do diff --git a/railties/lib/rails/test_help.rb b/railties/lib/rails/test_help.rb index 8bd4475c7b..9f6c42945f 100644 --- a/railties/lib/rails/test_help.rb +++ b/railties/lib/rails/test_help.rb @@ -17,7 +17,7 @@ if defined?(ActiveRecord) class ActiveSupport::TestCase include ActiveRecord::TestFixtures - self.fixture_path = "#{RAILS_ROOT}/test/fixtures/" + self.fixture_path = "#{Rails.root}/test/fixtures/" self.use_instantiated_fixtures = false self.use_transactional_fixtures = true end diff --git a/railties/lib/rails/vendor/thor-0.11.6/bin/rake2thor b/railties/lib/rails/vendor/thor-0.11.6/bin/rake2thor deleted file mode 100755 index 50c7410d80..0000000000 --- a/railties/lib/rails/vendor/thor-0.11.6/bin/rake2thor +++ /dev/null @@ -1,87 +0,0 @@ -#!/usr/bin/env ruby - -require 'rubygems' -require 'ruby2ruby' -require 'parse_tree' -if Ruby2Ruby::VERSION >= "1.2.0" - require 'parse_tree_extensions' -end -require 'rake' - -input = ARGV[0] || 'Rakefile' -output = ARGV[1] || 'Thorfile' - -$requires = [] - -module Kernel - def require_with_record(file) - $requires << file if caller[1] =~ /rake2thor:/ - require_without_record file - end - alias_method :require_without_record, :require - alias_method :require, :require_with_record -end - -load input - -@private_methods = [] - -def file_task_name(name) - "compile_" + name.gsub('/', '_slash_').gsub('.', '_dot_').gsub(/\W/, '_') -end - -def method_for_task(task) - file_task = task.is_a?(Rake::FileTask) - comment = task.instance_variable_get('@comment') - prereqs = task.instance_variable_get('@prerequisites').select(&Rake::Task.method(:task_defined?)) - actions = task.instance_variable_get('@actions') - name = task.name.gsub(/^([^:]+:)+/, '') - name = file_task_name(name) if file_task - meth = '' - - meth << "desc #{name.inspect}, #{comment.inspect}\n" if comment - meth << "def #{name}\n" - - meth << prereqs.map do |pre| - pre = pre.to_s - pre = file_task_name(pre) if Rake::Task[pre].is_a?(Rake::FileTask) - ' ' + pre - end.join("\n") - - meth << "\n\n" unless prereqs.empty? || actions.empty? - - meth << actions.map do |act| - act = act.to_ruby - unless act.gsub!(/^proc \{ \|(\w+)\|\n/, - " \\1 = Struct.new(:name).new(#{name.inspect}) # A crude mock Rake::Task object\n") - act.gsub!(/^proc \{\n/, '') - end - act.gsub(/\n\}$/, '') - end.join("\n") - - meth << "\nend" - - if file_task - @private_methods << meth - return - end - - meth -end - -body = Rake::Task.tasks.map(&method(:method_for_task)).compact.map { |meth| meth.gsub(/^/, ' ') }.join("\n\n") - -unless @private_methods.empty? - body << "\n\n private\n\n" - body << @private_methods.map { |meth| meth.gsub(/^/, ' ') }.join("\n\n") -end - -requires = $requires.map { |r| "require #{r.inspect}" }.join("\n") - -File.open(output, 'w') { |f| f.write(<<END.lstrip) } -#{requires} - -class Default < Thor -#{body} -end -END diff --git a/railties/lib/rails/vendor/thor-0.11.6/bin/thor b/railties/lib/rails/vendor/thor-0.11.6/bin/thor deleted file mode 100755 index eaf849fb4a..0000000000 --- a/railties/lib/rails/vendor/thor-0.11.6/bin/thor +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env ruby -# -*- mode: ruby -*- - -require File.join(File.dirname(__FILE__), '..', 'lib', 'thor') -require 'thor/runner' - -Thor::Runner.start diff --git a/railties/lib/rails/vendor/thor-0.11.6/CHANGELOG.rdoc b/railties/lib/rails/vendor/thor-0.11.8/CHANGELOG.rdoc index dba25b7205..dba25b7205 100644 --- a/railties/lib/rails/vendor/thor-0.11.6/CHANGELOG.rdoc +++ b/railties/lib/rails/vendor/thor-0.11.8/CHANGELOG.rdoc diff --git a/railties/lib/rails/vendor/thor-0.11.6/LICENSE b/railties/lib/rails/vendor/thor-0.11.8/LICENSE index 98722da459..98722da459 100644 --- a/railties/lib/rails/vendor/thor-0.11.6/LICENSE +++ b/railties/lib/rails/vendor/thor-0.11.8/LICENSE diff --git a/railties/lib/rails/vendor/thor-0.11.6/README.rdoc b/railties/lib/rails/vendor/thor-0.11.8/README.rdoc index f1106f02b6..f1106f02b6 100644 --- a/railties/lib/rails/vendor/thor-0.11.6/README.rdoc +++ b/railties/lib/rails/vendor/thor-0.11.8/README.rdoc diff --git a/railties/lib/rails/vendor/thor-0.11.8/Thorfile b/railties/lib/rails/vendor/thor-0.11.8/Thorfile new file mode 100644 index 0000000000..f71a1e57e2 --- /dev/null +++ b/railties/lib/rails/vendor/thor-0.11.8/Thorfile @@ -0,0 +1,63 @@ +# enconding: utf-8 + +require File.join(File.dirname(__FILE__), "lib", "thor", "version") +require 'thor/rake_compat' +require 'spec/rake/spectask' +require 'rdoc/task' + +GEM_NAME = 'thor' +EXTRA_RDOC_FILES = ["README.rdoc", "LICENSE", "CHANGELOG.rdoc", "VERSION", "Thorfile"] + +class Default < Thor + include Thor::RakeCompat + + Spec::Rake::SpecTask.new(:spec) do |t| + t.libs << 'lib' + t.spec_opts = ['--options', "spec/spec.opts"] + t.spec_files = FileList['spec/**/*_spec.rb'] + end + + Spec::Rake::SpecTask.new(:rcov) do |t| + t.libs << 'lib' + t.spec_opts = ['--options', "spec/spec.opts"] + t.spec_files = FileList['spec/**/*_spec.rb'] + t.rcov = true + t.rcov_dir = "rcov" + end + + RDoc::Task.new do |rdoc| + rdoc.main = "README.rdoc" + rdoc.rdoc_dir = "rdoc" + rdoc.title = GEM_NAME + rdoc.rdoc_files.include(*EXTRA_RDOC_FILES) + rdoc.rdoc_files.include('lib/**/*.rb') + rdoc.options << '--line-numbers' << '--inline-source' + end + + begin + require 'jeweler' + Jeweler::Tasks.new do |s| + s.name = GEM_NAME + s.version = Thor::VERSION + s.rubyforge_project = "textmate" + s.platform = Gem::Platform::RUBY + s.summary = "A scripting framework that replaces rake, sake and rubigen" + s.email = "ruby-thor@googlegroups.com" + s.homepage = "http://yehudakatz.com" + s.description = "A scripting framework that replaces rake, sake and rubigen" + s.authors = ['Yehuda Katz', 'José Valim'] + s.has_rdoc = true + s.extra_rdoc_files = EXTRA_RDOC_FILES + s.require_path = 'lib' + s.bindir = "bin" + s.executables = %w( thor rake2thor ) + s.files = s.extra_rdoc_files + Dir.glob("{bin,lib}/**/*") + s.files.exclude 'spec/sandbox/**/*' + s.test_files.exclude 'spec/sandbox/**/*' + end + + Jeweler::RubyforgeTasks.new + rescue LoadError + puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com" + end +end diff --git a/railties/lib/rails/vendor/thor-0.11.6/lib/thor.rb b/railties/lib/rails/vendor/thor-0.11.8/lib/thor.rb index 3b45c4e9b7..68944f140d 100644 --- a/railties/lib/rails/vendor/thor-0.11.6/lib/thor.rb +++ b/railties/lib/rails/vendor/thor-0.11.8/lib/thor.rb @@ -1,4 +1,3 @@ -$:.unshift File.expand_path(File.dirname(__FILE__)) require 'thor/base' require 'thor/group' require 'thor/actions' diff --git a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/actions.rb b/railties/lib/rails/vendor/thor-0.11.8/lib/thor/actions.rb index d561ccb2aa..d561ccb2aa 100644 --- a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/actions.rb +++ b/railties/lib/rails/vendor/thor-0.11.8/lib/thor/actions.rb diff --git a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/actions/create_file.rb b/railties/lib/rails/vendor/thor-0.11.8/lib/thor/actions/create_file.rb index 8f6badee27..8f6badee27 100644 --- a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/actions/create_file.rb +++ b/railties/lib/rails/vendor/thor-0.11.8/lib/thor/actions/create_file.rb diff --git a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/actions/directory.rb b/railties/lib/rails/vendor/thor-0.11.8/lib/thor/actions/directory.rb index be5eb822ac..063ac57406 100644 --- a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/actions/directory.rb +++ b/railties/lib/rails/vendor/thor-0.11.8/lib/thor/actions/directory.rb @@ -73,7 +73,9 @@ class Thor case file_source when /\.empty_directory$/ - base.empty_directory(File.dirname(file_destination), config) + dirname = File.dirname(file_destination).gsub(/\/\.$/, '') + next if dirname == given_destination + base.empty_directory(dirname, config) when /\.tt$/ base.template(file_source, file_destination[0..-4], config) else diff --git a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/actions/empty_directory.rb b/railties/lib/rails/vendor/thor-0.11.8/lib/thor/actions/empty_directory.rb index 03c1fe4af1..03c1fe4af1 100644 --- a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/actions/empty_directory.rb +++ b/railties/lib/rails/vendor/thor-0.11.8/lib/thor/actions/empty_directory.rb diff --git a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/actions/file_manipulation.rb b/railties/lib/rails/vendor/thor-0.11.8/lib/thor/actions/file_manipulation.rb index d77d90d448..d77d90d448 100644 --- a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/actions/file_manipulation.rb +++ b/railties/lib/rails/vendor/thor-0.11.8/lib/thor/actions/file_manipulation.rb diff --git a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/actions/inject_into_file.rb b/railties/lib/rails/vendor/thor-0.11.8/lib/thor/actions/inject_into_file.rb index 0636ec6591..0636ec6591 100644 --- a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/actions/inject_into_file.rb +++ b/railties/lib/rails/vendor/thor-0.11.8/lib/thor/actions/inject_into_file.rb diff --git a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/base.rb b/railties/lib/rails/vendor/thor-0.11.8/lib/thor/base.rb index 700d794123..700d794123 100644 --- a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/base.rb +++ b/railties/lib/rails/vendor/thor-0.11.8/lib/thor/base.rb diff --git a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/core_ext/hash_with_indifferent_access.rb b/railties/lib/rails/vendor/thor-0.11.8/lib/thor/core_ext/hash_with_indifferent_access.rb index 78bc5cf4bf..78bc5cf4bf 100644 --- a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/core_ext/hash_with_indifferent_access.rb +++ b/railties/lib/rails/vendor/thor-0.11.8/lib/thor/core_ext/hash_with_indifferent_access.rb diff --git a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/core_ext/ordered_hash.rb b/railties/lib/rails/vendor/thor-0.11.8/lib/thor/core_ext/ordered_hash.rb index 27fea5bb35..27fea5bb35 100644 --- a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/core_ext/ordered_hash.rb +++ b/railties/lib/rails/vendor/thor-0.11.8/lib/thor/core_ext/ordered_hash.rb diff --git a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/error.rb b/railties/lib/rails/vendor/thor-0.11.8/lib/thor/error.rb index f9b31a35d1..f9b31a35d1 100644 --- a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/error.rb +++ b/railties/lib/rails/vendor/thor-0.11.8/lib/thor/error.rb diff --git a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/group.rb b/railties/lib/rails/vendor/thor-0.11.8/lib/thor/group.rb index 1e59df2313..1e59df2313 100644 --- a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/group.rb +++ b/railties/lib/rails/vendor/thor-0.11.8/lib/thor/group.rb diff --git a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/invocation.rb b/railties/lib/rails/vendor/thor-0.11.8/lib/thor/invocation.rb index 32e6a72454..32e6a72454 100644 --- a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/invocation.rb +++ b/railties/lib/rails/vendor/thor-0.11.8/lib/thor/invocation.rb diff --git a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/parser.rb b/railties/lib/rails/vendor/thor-0.11.8/lib/thor/parser.rb index 57a3f6e1a5..57a3f6e1a5 100644 --- a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/parser.rb +++ b/railties/lib/rails/vendor/thor-0.11.8/lib/thor/parser.rb diff --git a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/parser/argument.rb b/railties/lib/rails/vendor/thor-0.11.8/lib/thor/parser/argument.rb index aa8ace4719..aa8ace4719 100644 --- a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/parser/argument.rb +++ b/railties/lib/rails/vendor/thor-0.11.8/lib/thor/parser/argument.rb diff --git a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/parser/arguments.rb b/railties/lib/rails/vendor/thor-0.11.8/lib/thor/parser/arguments.rb index fb5d965e06..fb5d965e06 100644 --- a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/parser/arguments.rb +++ b/railties/lib/rails/vendor/thor-0.11.8/lib/thor/parser/arguments.rb diff --git a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/parser/option.rb b/railties/lib/rails/vendor/thor-0.11.8/lib/thor/parser/option.rb index 9e40ec73fa..9e40ec73fa 100644 --- a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/parser/option.rb +++ b/railties/lib/rails/vendor/thor-0.11.8/lib/thor/parser/option.rb diff --git a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/parser/options.rb b/railties/lib/rails/vendor/thor-0.11.8/lib/thor/parser/options.rb index 75092308b5..75092308b5 100644 --- a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/parser/options.rb +++ b/railties/lib/rails/vendor/thor-0.11.8/lib/thor/parser/options.rb diff --git a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/rake_compat.rb b/railties/lib/rails/vendor/thor-0.11.8/lib/thor/rake_compat.rb index 3ab6bb21f5..0d0757fdda 100644 --- a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/rake_compat.rb +++ b/railties/lib/rails/vendor/thor-0.11.8/lib/thor/rake_compat.rb @@ -22,7 +22,8 @@ class Thor def self.included(base) # Hack. Make rakefile point to invoker, so rdoc task is generated properly. - Rake.application.instance_variable_set(:@rakefile, caller[0].match(/(.*):\d+/)[1]) + rakefile = File.basename(caller[0].match(/(.*):\d+/)[1]) + Rake.application.instance_variable_set(:@rakefile, rakefile) self.rake_classes << base end end @@ -43,11 +44,9 @@ class Object #:nodoc: description.strip! klass.desc description, task.comment || non_namespaced_name - klass.class_eval <<-METHOD - def #{non_namespaced_name}(#{task.arg_names.join(', ')}) - Rake::Task[#{task.name.to_sym.inspect}].invoke(#{task.arg_names.join(', ')}) - end - METHOD + klass.send :define_method, non_namespaced_name do |*args| + Rake::Task[task.name.to_sym].invoke(*args) + end end task diff --git a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/runner.rb b/railties/lib/rails/vendor/thor-0.11.8/lib/thor/runner.rb index 43da09b336..9dc70ea069 100644 --- a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/runner.rb +++ b/railties/lib/rails/vendor/thor-0.11.8/lib/thor/runner.rb @@ -215,7 +215,7 @@ class Thor::Runner < Thor #:nodoc: # 5. c:\ <-- no Thorfiles found! # def thorfiles(relevant_to=nil, skip_lookup=false) - # Deal with deprecated thor when :namespaces: is available as constants + # TODO Remove this dealing with deprecated thor when :namespaces: is available as constants save_yaml(thor_yaml) if Thor::Util.convert_constants_to_namespaces(thor_yaml) thorfiles = [] diff --git a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/shell.rb b/railties/lib/rails/vendor/thor-0.11.8/lib/thor/shell.rb index 0d3f4d5951..1dc8f0e5b4 100644 --- a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/shell.rb +++ b/railties/lib/rails/vendor/thor-0.11.8/lib/thor/shell.rb @@ -1,11 +1,17 @@ +require 'rbconfig' require 'thor/shell/color' class Thor module Base - # Returns the shell used in all Thor classes. Default to color one. + # Returns the shell used in all Thor classes. If you are in a Unix platform + # it will use a colored log, otherwise it will use a basic one without color. # def self.shell - @shell ||= Thor::Shell::Color + @shell ||= if Config::CONFIG['host_os'] =~ /mswin|mingw/ + Thor::Shell::Basic + else + Thor::Shell::Color + end end # Sets the shell used in all Thor classes. diff --git a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/shell/basic.rb b/railties/lib/rails/vendor/thor-0.11.8/lib/thor/shell/basic.rb index ea9665380b..ea9665380b 100644 --- a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/shell/basic.rb +++ b/railties/lib/rails/vendor/thor-0.11.8/lib/thor/shell/basic.rb diff --git a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/shell/color.rb b/railties/lib/rails/vendor/thor-0.11.8/lib/thor/shell/color.rb index 24704f7885..24704f7885 100644 --- a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/shell/color.rb +++ b/railties/lib/rails/vendor/thor-0.11.8/lib/thor/shell/color.rb diff --git a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/task.rb b/railties/lib/rails/vendor/thor-0.11.8/lib/thor/task.rb index 91c7564d3f..91c7564d3f 100644 --- a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/task.rb +++ b/railties/lib/rails/vendor/thor-0.11.8/lib/thor/task.rb diff --git a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/util.rb b/railties/lib/rails/vendor/thor-0.11.8/lib/thor/util.rb index fd820d7462..ebae0a3193 100644 --- a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/util.rb +++ b/railties/lib/rails/vendor/thor-0.11.8/lib/thor/util.rb @@ -209,7 +209,7 @@ class Thor # Returns the root where thor files are located, dependending on the OS. # def self.thor_root - File.join(user_home, ".thor") + File.join(user_home, ".thor").gsub(/\\/, '/') end # Returns the files in the thor root. On Windows thor_root will be something @@ -220,7 +220,7 @@ class Thor # If we don't #gsub the \ character, Dir.glob will fail. # def self.thor_root_glob - files = Dir["#{thor_root.gsub(/\\/, '/')}/*"] + files = Dir["#{thor_root}/*"] files.map! do |file| File.directory?(file) ? File.join(file, "main.thor") : file diff --git a/railties/lib/rails/vendor/thor-0.11.8/lib/thor/version.rb b/railties/lib/rails/vendor/thor-0.11.8/lib/thor/version.rb new file mode 100644 index 0000000000..885230fac4 --- /dev/null +++ b/railties/lib/rails/vendor/thor-0.11.8/lib/thor/version.rb @@ -0,0 +1,3 @@ +class Thor + VERSION = "0.11.8".freeze +end diff --git a/railties/lib/rails/vendor_gem_source_index.rb b/railties/lib/rails/vendor_gem_source_index.rb deleted file mode 100644 index 5b7721f303..0000000000 --- a/railties/lib/rails/vendor_gem_source_index.rb +++ /dev/null @@ -1,140 +0,0 @@ -require 'rubygems' -require 'yaml' - -module Rails - - class VendorGemSourceIndex - # VendorGemSourceIndex acts as a proxy for the Gem source index, allowing - # gems to be loaded from vendor/gems. Rather than the standard gem repository format, - # vendor/gems contains unpacked gems, with YAML specifications in .specification in - # each gem directory. - include Enumerable - - attr_reader :installed_source_index - attr_reader :vendor_source_index - - @@silence_spec_warnings = false - - def self.silence_spec_warnings - @@silence_spec_warnings - end - - def self.silence_spec_warnings=(v) - @@silence_spec_warnings = v - end - - def initialize(installed_index, vendor_dir=Rails::GemDependency.unpacked_path) - @installed_source_index = installed_index - @vendor_dir = vendor_dir - refresh! - end - - def refresh! - # reload the installed gems - @installed_source_index.refresh! - vendor_gems = {} - - # handle vendor Rails gems - they are identified by having loaded_from set to "" - # we add them manually to the list, so that other gems can find them via dependencies - Gem.loaded_specs.each do |n, s| - next unless s.loaded_from.empty? - vendor_gems[s.full_name] = s - end - - # load specifications from vendor/gems - Dir[File.join(Rails::GemDependency.unpacked_path, '*')].each do |d| - dir_name = File.basename(d) - dir_version = version_for_dir(dir_name) - spec = load_specification(d) - if spec - if spec.full_name != dir_name - # mismatched directory name and gem spec - produced by 2.1.0-era unpack code - if dir_version - # fix the spec version - this is not optimal (spec.files may be wrong) - # but it's better than breaking apps. Complain to remind users to get correct specs. - # use ActiveSupport::Deprecation.warn, as the logger is not set yet - $stderr.puts("config.gem: Unpacked gem #{dir_name} in vendor/gems has a mismatched specification file."+ - " Run 'rake gems:refresh_specs' to fix this.") unless @@silence_spec_warnings - spec.version = dir_version - else - $stderr.puts("config.gem: Unpacked gem #{dir_name} in vendor/gems is not in a versioned directory"+ - "(should be #{spec.full_name}).") unless @@silence_spec_warnings - # continue, assume everything is OK - end - end - else - # no spec - produced by early-2008 unpack code - # emulate old behavior, and complain. - $stderr.puts("config.gem: Unpacked gem #{dir_name} in vendor/gems has no specification file."+ - " Run 'rake gems:refresh_specs' to fix this.") unless @@silence_spec_warnings - if dir_version - spec = Gem::Specification.new - spec.version = dir_version - spec.require_paths = ['lib'] - ext_path = File.join(d, 'ext') - spec.require_paths << 'ext' if File.exist?(ext_path) - spec.name = /^(.*)-[^-]+$/.match(dir_name)[1] - files = ['lib'] - # set files to everything in lib/ - files += Dir[File.join(d, 'lib', '*')].map { |v| v.gsub(/^#{d}\//, '') } - files += Dir[File.join(d, 'ext', '*')].map { |v| v.gsub(/^#{d}\//, '') } if ext_path - spec.files = files - else - $stderr.puts("config.gem: Unpacked gem #{dir_name} in vendor/gems not in a versioned directory."+ - " Giving up.") unless @@silence_spec_warnings - next - end - end - spec.loaded_from = File.join(d, '.specification') - # finally, swap out full_gem_path - # it would be better to use a Gem::Specification subclass, but the YAML loads an explicit class - class << spec - def full_gem_path - path = File.join installation_path, full_name - return path if File.directory? path - File.join installation_path, original_name - end - end - vendor_gems[File.basename(d)] = spec - end - @vendor_source_index = Gem::SourceIndex.new(vendor_gems) - end - - def version_for_dir(d) - matches = /-([^-]+)$/.match(d) - Gem::Version.new(matches[1]) if matches - end - - def load_specification(gem_dir) - spec_file = File.join(gem_dir, '.specification') - YAML.load_file(spec_file) if File.exist?(spec_file) - end - - def find_name(*args) - @installed_source_index.find_name(*args) + @vendor_source_index.find_name(*args) - end - - def search(*args) - # look for vendor gems, and then installed gems - later elements take priority - @installed_source_index.search(*args) + @vendor_source_index.search(*args) - end - - def each(&block) - @vendor_source_index.each(&block) - @installed_source_index.each(&block) - end - - def add_spec(spec) - @vendor_source_index.add_spec spec - end - - def remove_spec(spec) - @vendor_source_index.remove_spec spec - end - - def size - @vendor_source_index.size + @installed_source_index.size - end - - end -end |