diff options
Diffstat (limited to 'activesupport/lib/active_support')
6 files changed, 56 insertions, 13 deletions
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 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/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) 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 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 diff --git a/activesupport/lib/active_support/lazy_load_hooks.rb b/activesupport/lib/active_support/lazy_load_hooks.rb index 642a4c105c..3664431a28 100644 --- a/activesupport/lib/active_support/lazy_load_hooks.rb +++ b/activesupport/lib/active_support/lazy_load_hooks.rb @@ -2,16 +2,26 @@ module ActiveSupport @load_hooks = Hash.new {|h,k| h[k] = [] } @loaded = {} - def self.on_load(name, &block) + def self.on_load(name, options = {}, &block) if base = @loaded[name] - base.instance_eval(&block) + execute_hook(base, options, block) else - @load_hooks[name] << block + @load_hooks[name] << [block, options] + end + end + + def self.execute_hook(base, options, block) + if options[:yield] + block.call(base) + else + base.instance_eval(&block) end end def self.run_load_hooks(name, base = Object) - @load_hooks[name].each { |hook| base.instance_eval(&hook) } @loaded[name] = base + @load_hooks[name].each do |hook, options| + execute_hook(base, options, hook) + end end end
\ No newline at end of file |