diff options
25 files changed, 157 insertions, 120 deletions
diff --git a/actionmailer/test/base_test.rb b/actionmailer/test/base_test.rb index fb42ccb8aa..c11081072d 100644 --- a/actionmailer/test/base_test.rb +++ b/actionmailer/test/base_test.rb @@ -209,6 +209,12 @@ class BaseTest < ActiveSupport::TestCase assert_equal "New Subject!", email.subject end + test "translations are scoped properly" do + I18n.backend.store_translations('en', :base_mailer => {:email_with_translations => {:greet_user => "Hello %{name}!"}}) + email = BaseMailer.email_with_translations + assert_equal 'Hello lifo!', email.body.encoded + end + # Implicit multipart test "implicit multipart" do email = BaseMailer.implicit_multipart diff --git a/actionmailer/test/fixtures/base_mailer/email_with_translations.html.erb b/actionmailer/test/fixtures/base_mailer/email_with_translations.html.erb new file mode 100644 index 0000000000..30466dd005 --- /dev/null +++ b/actionmailer/test/fixtures/base_mailer/email_with_translations.html.erb @@ -0,0 +1 @@ +<%= t('.greet_user', :name => 'lifo') %>
\ No newline at end of file diff --git a/actionmailer/test/mailers/base_mailer.rb b/actionmailer/test/mailers/base_mailer.rb index 2c6de36ccf..e89a5820cc 100644 --- a/actionmailer/test/mailers/base_mailer.rb +++ b/actionmailer/test/mailers/base_mailer.rb @@ -111,4 +111,8 @@ class BaseMailer < ActionMailer::Base format.html { render :layout => layout_name } end end + + def email_with_translations + body render("email_with_translations.html") + end end diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 66141c1de7..d7cfad7d6b 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,6 +1,15 @@ -*Support routing constraints in functional tests. [Andrew White] +* Symbols and strings in routes should yield the same behavior. Note this may break existing apps that were using symbols with the new routes API. [José Valim] -*Add a header that tells Internet Explorer (all versions) to use the best available standards support. [Yehuda Katz] +* Add clear_helpers as a way to clean up all helpers added to this controller, maintaing just the helper with the same name as the controller. [José Valim] + + +*Rails 3.0.0 [release candidate 2] (August 23rd, 2010)* + +* See http://github.com/rails/rails/compare/v3.0.0_RC...v3.0.0_RC2 for gory details + +* Support routing constraints in functional tests. [Andrew White] + +* Add a header that tells Internet Explorer (all versions) to use the best available standards support. [Yehuda Katz] *Rails 3.0.0 [release candidate] (July 26th, 2010)* diff --git a/actionpack/lib/abstract_controller.rb b/actionpack/lib/abstract_controller.rb index c565c940a1..f8fc79936f 100644 --- a/actionpack/lib/abstract_controller.rb +++ b/actionpack/lib/abstract_controller.rb @@ -2,6 +2,7 @@ activesupport_path = File.expand_path('../../../activesupport/lib', __FILE__) $:.unshift(activesupport_path) if File.directory?(activesupport_path) && !$:.include?(activesupport_path) require 'action_pack' +require 'active_support/concern' require 'active_support/ruby/shim' require 'active_support/dependencies/autoload' require 'active_support/core_ext/class/attribute' diff --git a/actionpack/lib/abstract_controller/helpers.rb b/actionpack/lib/abstract_controller/helpers.rb index 0c96a6ed15..a0ce121ade 100644 --- a/actionpack/lib/abstract_controller/helpers.rb +++ b/actionpack/lib/abstract_controller/helpers.rb @@ -95,6 +95,13 @@ module AbstractController _helpers.module_eval(&block) if block_given? end + # Clears up all existing helpers in this class, only keeping the helper + # with the same name as this class. + def clear_helpers + self._helpers = Module.new + default_helper_module! unless anonymous? + end + private # Makes all the (instance) methods in the helper module available to templates # rendered through this controller. diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index 165bf089c0..d8d3a2335a 100644 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -223,7 +223,7 @@ module ActionController def self.inherited(klass) super - klass.helper :all + klass.helper :all if klass.superclass == ActionController::Base end ActiveSupport.run_load_hooks(:action_controller, self) diff --git a/actionpack/lib/action_view/helpers/date_helper.rb b/actionpack/lib/action_view/helpers/date_helper.rb index 8050669adb..9891478606 100644 --- a/actionpack/lib/action_view/helpers/date_helper.rb +++ b/actionpack/lib/action_view/helpers/date_helper.rb @@ -1,6 +1,7 @@ -require "date" +require 'date' require 'action_view/helpers/tag_helper' require 'active_support/core_ext/hash/slice' +require 'active_support/core_ext/object/with_options' module ActionView module Helpers @@ -751,10 +752,8 @@ module ActionView # => [nil, "Jan", "Feb", "Mar", "Apr", "May", "Jun", # "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"] def translated_month_names - begin - key = @options[:use_short_month] ? :'date.abbr_month_names' : :'date.month_names' - I18n.translate(key, :locale => @options[:locale]) - end + key = @options[:use_short_month] ? :'date.abbr_month_names' : :'date.month_names' + I18n.translate(key, :locale => @options[:locale]) end # Lookup month name for number @@ -781,9 +780,7 @@ module ActionView memoize :date_order def translated_date_order - begin - I18n.translate(:'date.order', :locale => @options[:locale]) || [] - end + I18n.translate(:'date.order', :locale => @options[:locale]) || [] end # Build full select tag from date type and options @@ -837,15 +834,14 @@ module ActionView # prompt_option_tag(:month, :prompt => 'Select month') # => "<option value="">Select month</option>" def prompt_option_tag(type, options) - default_options = {:year => false, :month => false, :day => false, :hour => false, :minute => false, :second => false} - - case options - when Hash - prompt = default_options.merge(options)[type.to_sym] - when String - prompt = options - else - prompt = I18n.translate(('datetime.prompts.' + type.to_s).to_sym, :locale => @options[:locale]) + prompt = case options + when Hash + default_options = {:year => false, :month => false, :day => false, :hour => false, :minute => false, :second => false} + default_options.merge!(options)[type.to_sym] + when String + options + else + I18n.translate(:"datetime.prompts.#{type}", :locale => @options[:locale]) end prompt ? content_tag(:option, prompt, :value => '') : '' diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index ebe055bebd..938da7aea7 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -1006,9 +1006,14 @@ module ActionView def value_before_type_cast(object, method_name) unless object.nil? - object.respond_to?(method_name) ? - object.send(method_name) : - object.send(method_name + "_before_type_cast") + if object.respond_to?(method_name) + object.send(method_name) + # FIXME: this is AR dependent + elsif object.respond_to?(method_name + "_before_type_cast") + object.send(method_name + "_before_type_cast") + else + raise NoMethodError, "Model #{object.class} does not respond to #{method_name}" + end end end diff --git a/actionpack/lib/action_view/template.rb b/actionpack/lib/action_view/template.rb index 40ff1f2182..a999a0b7d7 100644 --- a/actionpack/lib/action_view/template.rb +++ b/actionpack/lib/action_view/template.rb @@ -1,5 +1,6 @@ require 'active_support/core_ext/array/wrap' require 'active_support/core_ext/object/blank' +require 'active_support/core_ext/object/try' require 'active_support/core_ext/kernel/singleton_class' module ActionView @@ -113,12 +114,11 @@ module ActionView @identifier = identifier @handler = handler @original_encoding = nil - - @virtual_path = details[:virtual_path] - @method_names = {} + @method_names = {} format = details[:format] || :html @formats = Array.wrap(format).map(&:to_sym) + @virtual_path = details[:virtual_path].try(:sub, ".#{format}", "") end def render(view, locals, &block) diff --git a/actionpack/test/abstract/helper_test.rb b/actionpack/test/abstract/helper_test.rb index 73941222dc..b28a5b5afb 100644 --- a/actionpack/test/abstract/helper_test.rb +++ b/actionpack/test/abstract/helper_test.rb @@ -38,6 +38,10 @@ module AbstractController end end + class ::HelperyTestController < AbstractHelpers + clear_helpers + end + class AbstractHelpersBlock < ControllerWithHelpers helper do include ::AbstractController::Testing::HelperyTest @@ -45,7 +49,6 @@ module AbstractController end class TestHelpers < ActiveSupport::TestCase - def setup @controller = AbstractHelpers.new end @@ -74,8 +77,22 @@ module AbstractController @controller.process(:with_module) assert_equal "Module Included", @controller.response_body end - end + class ClearHelpersTest < ActiveSupport::TestCase + def setup + @controller = HelperyTestController.new + end + + def test_clears_up_previous_helpers + @controller.process(:with_symbol) + assert_equal "I respond to bare_a: false", @controller.response_body + end + + def test_includes_controller_default_helper + @controller.process(:with_block) + assert_equal "Hello Default", @controller.response_body + end + end end end diff --git a/actionpack/test/controller/helper_test.rb b/actionpack/test/controller/helper_test.rb index ad66f138eb..4f8ff4140f 100644 --- a/actionpack/test/controller/helper_test.rb +++ b/actionpack/test/controller/helper_test.rb @@ -25,6 +25,13 @@ class AllHelpersController < ActionController::Base helper :all end +class JustMeController < ActionController::Base + clear_helpers +end + +class MeTooController < JustMeController +end + module LocalAbcHelper def a() end def b() end @@ -92,6 +99,11 @@ class HelperTest < ActiveSupport::TestCase # assert_equal 'test: baz', Fun::PdfController.process(request, response).body end + def test_default_helpers_only + assert_equal [JustMeHelper], JustMeController._helpers.ancestors.reject(&:anonymous?) + assert_equal [MeTooHelper, JustMeHelper], MeTooController._helpers.ancestors.reject(&:anonymous?) + end + def test_all_helpers methods = AllHelpersController._helpers.instance_methods.map {|m| m.to_s} diff --git a/actionpack/test/fixtures/helpers/helpery_test_helper.rb b/actionpack/test/fixtures/helpers/helpery_test_helper.rb new file mode 100644 index 0000000000..a4f2951efa --- /dev/null +++ b/actionpack/test/fixtures/helpers/helpery_test_helper.rb @@ -0,0 +1,5 @@ +module HelperyTestHelper + def helpery_test + "Default" + end +end diff --git a/actionpack/test/fixtures/helpers/just_me_helper.rb b/actionpack/test/fixtures/helpers/just_me_helper.rb new file mode 100644 index 0000000000..b140a7b9b4 --- /dev/null +++ b/actionpack/test/fixtures/helpers/just_me_helper.rb @@ -0,0 +1,3 @@ +module JustMeHelper + def me() "mine!" end +end
\ No newline at end of file diff --git a/actionpack/test/fixtures/helpers/me_too_helper.rb b/actionpack/test/fixtures/helpers/me_too_helper.rb new file mode 100644 index 0000000000..ce56042143 --- /dev/null +++ b/actionpack/test/fixtures/helpers/me_too_helper.rb @@ -0,0 +1,3 @@ +module MeTooHelper + def me() "me too!" end +end
\ No newline at end of file diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index 71a5ae0245..8ba4aa1639 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -12,6 +12,8 @@ class FormHelperTest < ActionView::TestCase def name "Santiago" end + + attr_writer :language end def form_for(*) @@ -257,6 +259,17 @@ class FormHelperTest < ActionView::TestCase ) end + def test_text_field_on_a_model_with_undefined_attr_reader + @developer = Developer.new + @developer.language = 'ruby' + begin + text_field("developer", "language") + rescue NoMethodError => error + message = error.message + end + assert_equal "Model #{Developer} does not respond to language", message + end + def test_check_box assert_dom_equal( '<input name="post[secret]" type="hidden" value="0" /><input checked="checked" id="post_secret" name="post[secret]" type="checkbox" value="1" />', diff --git a/activerecord/lib/active_record/railties/databases.rake b/activerecord/lib/active_record/railties/databases.rake index b46c4b59a2..b1aad0d496 100644 --- a/activerecord/lib/active_record/railties/databases.rake +++ b/activerecord/lib/active_record/railties/databases.rake @@ -61,7 +61,7 @@ namespace :db do @charset = ENV['CHARSET'] || 'utf8' @collation = ENV['COLLATION'] || 'utf8_unicode_ci' creation_options = {:charset => (config['charset'] || @charset), :collation => (config['collation'] || @collation)} - error_class = config['adapter'] == 'mysql2' ? Mysql2::Error : Mysql::Error + error_class = config['adapter'] =~ /mysql2/ ? Mysql2::Error : Mysql::Error access_denied_error = 1045 begin ActiveRecord::Base.establish_connection(config.merge('database' => nil)) diff --git a/railties/guides/rails_guides/generator.rb b/railties/guides/rails_guides/generator.rb index 5a5ce54503..eaa9d79ce8 100644 --- a/railties/guides/rails_guides/generator.rb +++ b/railties/guides/rails_guides/generator.rb @@ -237,8 +237,9 @@ module RailsGuides end end - # Also, footnotes are rendered as paragraphs this way. + # Footnotes. anchors += Set.new(html.scan(/<p\s+class="footnote"\s+id="([^"]+)/).flatten) + anchors += Set.new(html.scan(/<sup\s+class="footnote"\s+id="([^"]+)/).flatten) return anchors end diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index 561bae3be8..696db30efb 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -1685,27 +1685,7 @@ foreign_key = options[:foreign_key] || reflection.active_record.name.foreign_key NOTE: Defined in +active_support/core_ext/string/inflections.rb+. -h4. Conversions - -h5. +constantize+ - -The method +constantize+ expects the receiver to contain the name of a constant, and tries to get you the object stored in there, assuming it is defined: - -<ruby> -"ActiveRecord::Base".constantize # => ActiveRecord::Base -</ruby> - -The name is assumed to be top-level, no matter whether it starts with "::" or not. No lexical context is taken into account: - -<ruby> -C = 1 -module M - C = 2 - "C".constantize # => 1, same as "::C".constantize -end -</ruby> - -NOTE: Defined in +active_support/core_ext/string/conversions.rb+. +h4(#string-conversions). Conversions h5. +ord+ @@ -2041,7 +2021,7 @@ This method receives an arbitrary number of action names, and an optional hash o NOTE: Defined in +active_support/core_ext/array/extract_options.rb+. -h4. Conversions +h4(#array-conversions). Conversions h5. +to_sentence+ @@ -2985,7 +2965,7 @@ Date.new(2010, 1, 31).change(:month => 2) # => ArgumentError: invalid date </ruby> -h5. Durations +h5(#date-durations). Durations Durations can be added and substracted to dates: @@ -3191,7 +3171,7 @@ DateTime.current.change(:month => 2, :day => 30) # => ArgumentError: invalid date </ruby> -h5. Durations +h5(#datetime-durations). Durations Durations can be added and substracted to datetimes: @@ -3304,7 +3284,7 @@ Both +local_time+ and +utc_time+ accept up to seven positional arguments: year, If the time to be constructed lies beyond the range supported by +Time+ in the runtime platform, usecs are discarded and a +DateTime+ object is returned instead. -h5. Durations +h5(#time-durations). Durations Durations can be added and substracted to time objects: diff --git a/railties/guides/source/association_basics.textile b/railties/guides/source/association_basics.textile index 17742a8d8c..dbef9463a9 100644 --- a/railties/guides/source/association_basics.textile +++ b/railties/guides/source/association_basics.textile @@ -550,7 +550,7 @@ build_customer create_customer </ruby> -h6. <em>association</em>(force_reload = false) +h6. <tt>_association_(force_reload = false)</tt> The <tt><em>association</em></tt> method returns the associated object, if any. If no associated object is found, it returns +nil+. @@ -560,7 +560,7 @@ The <tt><em>association</em></tt> method returns the associated object, if any. If the associated object has already been retrieved from the database for this object, the cached version will be returned. To override this behavior (and force a database read), pass +true+ as the +force_reload+ argument. -h6. _association_=(associate) +h6. <tt>_association_=(associate)</tt> The <tt><em>association</em>=</tt> method assigns an associated object to this object. Behind the scenes, this means extracting the primary key from the associate object and setting this object's foreign key to the same value. @@ -568,7 +568,7 @@ The <tt><em>association</em>=</tt> method assigns an associated object to this o @order.customer = @customer </ruby> -h6. build_<em>association</em>(attributes = {}) +h6(#belongs_to-build_association). <tt>build_<em>association</em>(attributes = {})</tt> The <tt>build_<em>association</em></tt> method returns a new object of the associated type. This object will be instantiated from the passed attributes, and the link through this object's foreign key will be set, but the associated object will _not_ yet be saved. @@ -577,7 +577,7 @@ The <tt>build_<em>association</em></tt> method returns a new object of the assoc :customer_name => "John Doe") </ruby> -h6. create_<em>association</em>(attributes = {}) +h6(#belongs_to-create_association). <tt>create_<em>association</em>(attributes = {})</tt> The <tt>create_<em>association</em></tt> method returns a new object of the associated type. This object will be instantiated from the passed attributes, and the link through this object's foreign key will be set. In addition, the associated object _will_ be saved (assuming that it passes any validations). @@ -835,7 +835,7 @@ The <tt><em>association</em>=</tt> method assigns an associated object to this o @supplier.account = @account </ruby> -h6. <tt>build_<em>association</em>(attributes = {})</tt> +h6(#has_one-build_association). <tt>build_<em>association</em>(attributes = {})</tt> The <tt>build_<em>association</em></tt> method returns a new object of the associated type. This object will be instantiated from the passed attributes, and the link through its foreign key will be set, but the associated object will _not_ yet be saved. @@ -843,7 +843,7 @@ The <tt>build_<em>association</em></tt> method returns a new object of the assoc @account = @supplier.build_account(:terms => "Net 30") </ruby> -h6. <tt>create_<em>association</em>(attributes = {})</tt> +h6(#has_one-create_association). <tt>create_<em>association</em>(attributes = {})</tt> The <tt>create_<em>association</em></tt> method returns a new object of the associated type. This object will be instantiated from the passed attributes, and the link through its foreign key will be set. In addition, the associated object _will_ be saved (assuming that it passes any validations). @@ -985,7 +985,7 @@ The +:source_type+ option specifies the source association type for a +has_one : h6(#has_one-through). +:through+ -The +:through+ option specifies a join model through which to perform the query. +has_one :through+ associations were discussed in detail <a href="#the-has-one-through-association">earlier in this guide</a>. +The +:through+ option specifies a join model through which to perform the query. +has_one :through+ associations were discussed in detail <a href="#the-has_one-through-association">earlier in this guide</a>. h6(#has_one-validate). +:validate+ @@ -1136,7 +1136,7 @@ h6. <tt><em>collection</em>.exists?(...)</tt> The <tt><em>collection</em>.exists?</tt> method checks whether an object meeting the supplied conditions exists in the collection. It uses the same syntax and options as +ActiveRecord::Base.exists?+. -h6. <tt><em>collection</em>.build(attributes = {}, ...)</tt> +h6(#has_many_collection_build). <tt><em>collection</em>.build(attributes = {}, ...)</tt> The <tt><em>collection</em>.build</tt> method returns one or more new objects of the associated type. These objects will be instantiated from the passed attributes, and the link through their foreign key will be created, but the associated objects will _not_ yet be saved. @@ -1367,7 +1367,7 @@ The +:source_type+ option specifies the source association type for a +has_many h6(#has_many-through). +:through+ -The +:through+ option specifies a join model through which to perform the query. +has_many :through+ associations provide a way to implement many-to-many relationships, as discussed <a href="#the-has-many-through-association">earlier in this guide</a>. +The +:through+ option specifies a join model through which to perform the query. +has_many :through+ associations provide a way to implement many-to-many relationships, as discussed <a href="#the-has_many-through-association">earlier in this guide</a>. h6(#has_many-uniq). +:uniq+ @@ -1553,7 +1553,7 @@ h6(#has_and_belongs_to_many-collection-exists). <tt><em>collection</em>.exists?( The <tt><em>collection</em>.exists?</tt> method checks whether an object meeting the supplied conditions exists in the collection. It uses the same syntax and options as +ActiveRecord::Base.exists?+. -h6. <tt><em>collection</em>.build(attributes = {})</tt> +h6(#has_and_belongs_to_many-collection-build). <tt><em>collection</em>.build(attributes = {})</tt> The <tt><em>collection</em>.build</tt> method returns a new object of the associated type. This object will be instantiated from the passed attributes, and the link through the join table will be created, but the associated object will _not_ yet be saved. diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index 48393d2156..49c1049cc7 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -1448,6 +1448,7 @@ h3. What's Next? Now that you've seen your first Rails application, you should feel free to update it and experiment on your own. But you don't have to do everything without help. As you need assistance getting up and running with Rails, feel free to consult these support resources: * The "Ruby on Rails guides":index.html +* The "Ruby on Rails Tutorial":http://railstutorial.org/book * The "Ruby on Rails mailing list":http://groups.google.com/group/rubyonrails-talk * The "#rubyonrails":irc://irc.freenode.net/#rubyonrails channel on irc.freenode.net * The "Rails Wiki":http://wiki.rubyonrails.org/ diff --git a/railties/guides/source/index.html.erb b/railties/guides/source/index.html.erb index a0db87c188..84e25dd0e9 100644 --- a/railties/guides/source/index.html.erb +++ b/railties/guides/source/index.html.erb @@ -140,7 +140,7 @@ Ruby on Rails Guides <p>This guide covers Rails integration with Rack and interfacing with other Rack components.</p> <% end %> - <%= guide("Adding Generators", 'generators.html') do %> + <%= guide("Creating and Customizing Rails Generators", 'generators.html') do %> <p>This guide covers the process of adding a brand new generator to your extension or providing an alternative to an element of a built-in Rails generator (such as providing alternative test stubs for the scaffold generator).</p> diff --git a/railties/guides/source/layout.html.erb b/railties/guides/source/layout.html.erb index cc7d54c256..2039c76213 100644 --- a/railties/guides/source/layout.html.erb +++ b/railties/guides/source/layout.html.erb @@ -76,7 +76,7 @@ <dt>Extending Rails</dt> <dd><a href="plugins.html">The Basics of Creating Rails Plugins</a></dd> <dd><a href="rails_on_rack.html">Rails on Rack</a></dd> - <dd><a href="generators.html">Adding a Generator to Your Plugin</a></dd> + <dd><a href="generators.html">Creating and Customizing Rails Generators</a></dd> <dt>Contributing to Rails</dt> <dd><a href="contributing_to_rails.html">Contributing to Rails</a></dd> diff --git a/railties/lib/rails/cli.rb b/railties/lib/rails/cli.rb index d49431919d..1260772605 100644 --- a/railties/lib/rails/cli.rb +++ b/railties/lib/rails/cli.rb @@ -1,6 +1,8 @@ require 'rbconfig' require 'rails/script_rails_loader' +# If we are inside a Rails application this method performs an exec and thus +# the rest of this script is not run. Rails::ScriptRailsLoader.exec_script_rails! railties_path = File.expand_path('../../lib', __FILE__) diff --git a/railties/lib/rails/deprecation.rb b/railties/lib/rails/deprecation.rb index 1eb6d804b6..37896e0cae 100644 --- a/railties/lib/rails/deprecation.rb +++ b/railties/lib/rails/deprecation.rb @@ -1,62 +1,33 @@ require "active_support/string_inquirer" -require "active_support/deprecation" +require "active_support/basic_object" -RAILS_ROOT = (Class.new(ActiveSupport::Deprecation::DeprecationProxy) do - cattr_accessor :warned - self.warned = false - - def target - Rails.root - end - - def replace(*args) - warn(caller, :replace, *args) - end - - def warn(callstack, called, args) - unless warned - ActiveSupport::Deprecation.warn("RAILS_ROOT is deprecated! Use Rails.root instead", callstack) - self.warned = true +module Rails + class DeprecatedConstant < ActiveSupport::BasicObject + def self.deprecate(old, new) + constant = self.new(old, new) + eval "::#{old} = constant" end - end -end).new - -RAILS_ENV = (Class.new(ActiveSupport::Deprecation::DeprecationProxy) do - cattr_accessor :warned - self.warned = false - - def target - Rails.env - end - def replace(*args) - warn(caller, :replace, *args) - end - - def warn(callstack, called, args) - unless warned - ActiveSupport::Deprecation.warn("RAILS_ENV is deprecated! Use Rails.env instead", callstack) - self.warned = true + def initialize(old, new) + @old, @new = old, new + @target = ::Kernel.eval "proc { #{@new} }" + @warned = false end - end -end).new - -RAILS_DEFAULT_LOGGER = (Class.new(ActiveSupport::Deprecation::DeprecationProxy) do - cattr_accessor :warned - self.warned = false - def target - Rails.logger - end - - def replace(*args) - warn(caller, :replace, *args) - end + def method_missing(meth, *args, &block) + ::ActiveSupport::Deprecation.warn("#{@old} is deprecated. Please use #{@new}") unless @warned + @warned = true - def warn(callstack, called, args) - unless warned - ActiveSupport::Deprecation.warn("RAILS_DEFAULT_LOGGER is deprecated! Use Rails.logger instead", callstack) - self.warned = true + target = @target.call + if target.respond_to?(meth) + target.send(meth, *args, &block) + else + super + end end end -end).new + + DeprecatedConstant.deprecate("RAILS_ROOT", "::Rails.root.to_s") + DeprecatedConstant.deprecate("RAILS_ENV", "::Rails.env") + DeprecatedConstant.deprecate("RAILS_DEFAULT_LOGGER", "::Rails.logger") +end |