From 2203c781a7dfa8b0c8b6c97cd318d941f9fbb26c Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Wed, 12 May 2010 23:04:17 +0200 Subject: defines prev_(month|year) in Date and Time to ease transition to 1.9, and deprecates last_(month|year) --- .../active_support/core_ext/date/calculations.rb | 21 ++++++++++++++++----- .../active_support/core_ext/time/calculations.rb | 14 ++++++++++++-- 2 files changed, 28 insertions(+), 7 deletions(-) (limited to 'activesupport/lib/active_support/core_ext') diff --git a/activesupport/lib/active_support/core_ext/date/calculations.rb b/activesupport/lib/active_support/core_ext/date/calculations.rb index 3038729d34..755d96ce91 100644 --- a/activesupport/lib/active_support/core_ext/date/calculations.rb +++ b/activesupport/lib/active_support/core_ext/date/calculations.rb @@ -2,6 +2,7 @@ require 'date' require 'active_support/duration' require 'active_support/core_ext/time/zones' require 'active_support/core_ext/object/acts_like' +require 'active_support/deprecation' class Date if RUBY_VERSION < '1.9' @@ -146,20 +147,30 @@ class Date advance(:years => years) end - # Short-hand for years_ago(1) - def last_year - years_ago(1) + def last_year # :nodoc: + ActiveSupport::Deprecation.warn("Date#last_year has been deprecated, please use Date#prev_year instead", caller) + prev_year end + # Shorthand for years_ago(1) + def prev_year + years_ago(1) + end unless method_defined?(:prev_year) + # Short-hand for years_since(1) def next_year years_since(1) end unless method_defined?(:next_year) + def last_month # :nodoc: + ActiveSupport::Deprecation.warn("Date#last_month has been deprecated, please use Date#prev_month instead", caller) + prev_month + end + # Short-hand for months_ago(1) - def last_month + def prev_month months_ago(1) - end + end unless method_defined?(:prev_month) # Short-hand for months_since(1) def next_month diff --git a/activesupport/lib/active_support/core_ext/time/calculations.rb b/activesupport/lib/active_support/core_ext/time/calculations.rb index 2b47ecd543..e27b08ec2e 100644 --- a/activesupport/lib/active_support/core_ext/time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/time/calculations.rb @@ -2,6 +2,7 @@ require 'active_support/duration' require 'active_support/core_ext/date/acts_like' require 'active_support/core_ext/date/calculations' require 'active_support/core_ext/date_time/conversions' +require 'active_support/deprecation' class Time COMMON_YEAR_DAYS_IN_MONTH = [nil, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] @@ -132,8 +133,13 @@ class Time advance(:years => years) end + def last_year # :nodoc: + ActiveSupport::Deprecation.warn("Time#last_year has been deprecated, please use Time#prev_year instead", caller) + prev_year + end + # Short-hand for years_ago(1) - def last_year + def prev_year years_ago(1) end @@ -142,9 +148,13 @@ class Time years_since(1) end + def last_month # :nodoc: + ActiveSupport::Deprecation.warn("Time#last_month has been deprecated, please use Time#prev_month instead", caller) + prev_month + end # Short-hand for months_ago(1) - def last_month + def prev_month months_ago(1) end -- cgit v1.2.3 From a0621c1086165e4b3cff71b54f08a190851b6314 Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Fri, 14 May 2010 15:10:10 -0400 Subject: Better code formatting and proper line numbers for stack traces [#4596 state:resolved] Signed-off-by: Jeremy Kemper --- activesupport/lib/active_support/core_ext/logger.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport/lib/active_support/core_ext') diff --git a/activesupport/lib/active_support/core_ext/logger.rb b/activesupport/lib/active_support/core_ext/logger.rb index 22749229a3..c4994ca2ee 100644 --- a/activesupport/lib/active_support/core_ext/logger.rb +++ b/activesupport/lib/active_support/core_ext/logger.rb @@ -3,7 +3,7 @@ require 'active_support/core_ext/class/attribute_accessors' # Adds the 'around_level' method to Logger. class Logger #:nodoc: def self.define_around_helper(level) - module_eval <<-end_eval + module_eval <<-end_eval, __FILE__, __LINE__ + 1 def around_#{level}(before_message, after_message, &block) # def around_debug(before_message, after_message, &block) self.#{level}(before_message) # self.debug(before_message) return_value = block.call(self) # return_value = block.call(self) -- cgit v1.2.3 From c77794a924938360bf4e61c9a13cdbe5b58fdf62 Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Sat, 15 May 2010 09:12:55 -0300 Subject: Add missing require to with_options [#4601 state:resolved] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- activesupport/lib/active_support/core_ext/object/with_options.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'activesupport/lib/active_support/core_ext') diff --git a/activesupport/lib/active_support/core_ext/object/with_options.rb b/activesupport/lib/active_support/core_ext/object/with_options.rb index dd38b7d261..3209cf7f11 100644 --- a/activesupport/lib/active_support/core_ext/object/with_options.rb +++ b/activesupport/lib/active_support/core_ext/object/with_options.rb @@ -1,3 +1,5 @@ +require 'active_support/option_merger' + class Object # An elegant way to factor duplication out of options passed to a series of # method calls. Each method called in the block, with the block variable as -- cgit v1.2.3 From af0d1a88157942c6e6398dbf73891cff1e152405 Mon Sep 17 00:00:00 2001 From: wycats Date: Sat, 15 May 2010 03:47:24 -0700 Subject: Initial work to improve the state of encodings for templates --- activesupport/lib/active_support/core_ext/string/encoding.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 activesupport/lib/active_support/core_ext/string/encoding.rb (limited to 'activesupport/lib/active_support/core_ext') diff --git a/activesupport/lib/active_support/core_ext/string/encoding.rb b/activesupport/lib/active_support/core_ext/string/encoding.rb new file mode 100644 index 0000000000..d4781bfe0c --- /dev/null +++ b/activesupport/lib/active_support/core_ext/string/encoding.rb @@ -0,0 +1,11 @@ +class String + if defined?(Encoding) && "".respond_to?(:encode) + def encoding_aware? + true + end + else + def encoding_aware? + false + end + end +end \ No newline at end of file -- cgit v1.2.3 From 821e15e5f2d9ef2aa43918a16cbd00f40c221e95 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Sun, 16 May 2010 15:20:52 -0300 Subject: Change on Array extension from rand => random_element [#4555 state:committed] Signed-off-by: Xavier Noria --- .../lib/active_support/core_ext/array/random_access.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'activesupport/lib/active_support/core_ext') diff --git a/activesupport/lib/active_support/core_ext/array/random_access.rb b/activesupport/lib/active_support/core_ext/array/random_access.rb index 343003f6f7..5338836b29 100644 --- a/activesupport/lib/active_support/core_ext/array/random_access.rb +++ b/activesupport/lib/active_support/core_ext/array/random_access.rb @@ -1,6 +1,16 @@ class Array + # This method is deprecated because it masks Kernel#rand within the Array class itself, + # which may be used by a 3rd party library extending Array in turn. See + # + # https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/4555 + # + def rand # :nodoc: + ActiveSupport::Deprecation.warn "Array#rand is deprecated, use random_element instead", caller + random_element + end + # Returns a random element from the array. - def rand + def random_element self[Kernel.rand(length)] end end -- cgit v1.2.3 From ade756fe42423033bae8e5aea8f58782f7a6c517 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sun, 16 May 2010 13:52:51 -0700 Subject: Moved encoding work in progress to a feature branch. This reverts commits af0d1a88157942c6e6398dbf73891cff1e152405 and 64d109e3539ad600f58536d3ecabd2f87b67fd1c. --- activesupport/lib/active_support/core_ext/string/encoding.rb | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 activesupport/lib/active_support/core_ext/string/encoding.rb (limited to 'activesupport/lib/active_support/core_ext') diff --git a/activesupport/lib/active_support/core_ext/string/encoding.rb b/activesupport/lib/active_support/core_ext/string/encoding.rb deleted file mode 100644 index d4781bfe0c..0000000000 --- a/activesupport/lib/active_support/core_ext/string/encoding.rb +++ /dev/null @@ -1,11 +0,0 @@ -class String - if defined?(Encoding) && "".respond_to?(:encode) - def encoding_aware? - true - end - else - def encoding_aware? - false - end - end -end \ No newline at end of file -- cgit v1.2.3