diff options
author | Guillermo Álvarez <guillermo@cientifico.net> | 2009-02-07 19:16:15 +0100 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2009-02-22 16:11:40 +0100 |
commit | ff1afbd65098643a06eef928f92fecf6e9d548b2 (patch) | |
tree | 9cdef532d73a1f31383cb11df8fb95f3dc46243a /activesupport/lib | |
parent | b61cad6ae140bc71c6a74b22c75e886b41154b0a (diff) | |
download | rails-ff1afbd65098643a06eef928f92fecf6e9d548b2.tar.gz rails-ff1afbd65098643a06eef928f92fecf6e9d548b2.tar.bz2 rails-ff1afbd65098643a06eef928f92fecf6e9d548b2.zip |
Deprecated warnings for :skip_last_command and :connector of to_sentence [#1847 state:committed]
Signed-off-by: David Heinemeier Hansson <david@loudthinking.com>
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/core_ext/array/conversions.rb | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/activesupport/lib/active_support/core_ext/array/conversions.rb b/activesupport/lib/active_support/core_ext/array/conversions.rb index 69d35dafd3..a9b50ca92d 100644 --- a/activesupport/lib/active_support/core_ext/array/conversions.rb +++ b/activesupport/lib/active_support/core_ext/array/conversions.rb @@ -6,14 +6,28 @@ module ActiveSupport #:nodoc: # * <tt>:words_connector</tt> - The sign or word used to join the elements in arrays with two or more elements (default: ", ") # * <tt>:two_words_connector</tt> - The sign or word used to join the elements in arrays with two elements (default: " and ") # * <tt>:last_word_connector</tt> - The sign or word used to join the last element in arrays with three or more elements (default: ", and ") - def to_sentence(options = {}) - options.assert_valid_keys(:words_connector, :two_words_connector, :last_word_connector, :locale) - + def to_sentence(options = {}) + default_words_connector = I18n.translate(:'support.array.words_connector', :locale => options[:locale]) default_two_words_connector = I18n.translate(:'support.array.two_words_connector', :locale => options[:locale]) - default_last_word_connector = I18n.translate(:'support.array.last_word_connector', :locale => options[:locale]) - options.reverse_merge! :words_connector => default_words_connector, :two_words_connector => default_two_words_connector, :last_word_connector => default_last_word_connector + default_last_word_connector = I18n.translate(:'support.array.last_word_connector', :locale => options[:locale]) + # Try to emulate to_senteces previous to 2.3 + if options.has_key?(:connector) || options.has_key?(:skip_last_comma) + ::ActiveSupport::Deprecation.warn(":connector has been deprecated. Use :words_connector instead", caller) if options.has_key? :connector + ::ActiveSupport::Deprecation.warn(":skip_last_comma has been deprecated. Use :last_word_connector instead", caller) if options.has_key? :skip_last_comma + + skip_last_comma = options.delete :skip_last_comma + if connector = options.delete(:connector) + options[:last_word_connector] ||= skip_last_comma ? connector : ", #{connector}" + else + options[:last_word_connector] ||= skip_last_comma ? default_two_words_connector : default_last_word_connector + end + end + + options.assert_valid_keys(:words_connector, :two_words_connector, :last_word_connector, :locale) + options.reverse_merge! :words_connector => default_words_connector, :two_words_connector => default_two_words_connector, :last_word_connector => default_last_word_connector + case length when 0 "" |