diff options
Diffstat (limited to 'activesupport/lib')
5 files changed, 38 insertions, 80 deletions
diff --git a/activesupport/lib/active_support/core_ext/class/attribute.rb b/activesupport/lib/active_support/core_ext/class/attribute.rb index 79d5c40e5f..688cba03db 100644 --- a/activesupport/lib/active_support/core_ext/class/attribute.rb +++ b/activesupport/lib/active_support/core_ext/class/attribute.rb @@ -72,6 +72,7 @@ class Class remove_possible_method(:#{name}) define_method(:#{name}) { val } end + val end def #{name} diff --git a/activesupport/lib/active_support/core_ext/object.rb b/activesupport/lib/active_support/core_ext/object.rb index d671da6711..790a26f5c1 100644 --- a/activesupport/lib/active_support/core_ext/object.rb +++ b/activesupport/lib/active_support/core_ext/object.rb @@ -2,7 +2,6 @@ require 'active_support/core_ext/object/acts_like' require 'active_support/core_ext/object/blank' require 'active_support/core_ext/object/duplicable' require 'active_support/core_ext/object/try' -require 'active_support/core_ext/object/returning' require 'active_support/core_ext/object/conversions' require 'active_support/core_ext/object/instance_variables' diff --git a/activesupport/lib/active_support/core_ext/object/returning.rb b/activesupport/lib/active_support/core_ext/object/returning.rb deleted file mode 100644 index c401992ccc..0000000000 --- a/activesupport/lib/active_support/core_ext/object/returning.rb +++ /dev/null @@ -1,43 +0,0 @@ -class Object - # Returns +value+ after yielding +value+ to the block. This simplifies the - # process of constructing an object, performing work on the object, and then - # returning the object from a method. It is a Ruby-ized realization of the K - # combinator, courtesy of Mikael Brockman. - # - # ==== Examples - # - # # Without returning - # def foo - # values = [] - # values << "bar" - # values << "baz" - # return values - # end - # - # foo # => ['bar', 'baz'] - # - # # returning with a local variable - # def foo - # returning values = [] do - # values << 'bar' - # values << 'baz' - # end - # end - # - # foo # => ['bar', 'baz'] - # - # # returning with a block argument - # def foo - # returning [] do |values| - # values << 'bar' - # values << 'baz' - # end - # end - # - # foo # => ['bar', 'baz'] - def returning(value) - ActiveSupport::Deprecation.warn('Object#returning has been deprecated in favor of Object#tap.', caller) - yield(value) - value - end -end
\ No newline at end of file diff --git a/activesupport/lib/active_support/log_subscriber.rb b/activesupport/lib/active_support/log_subscriber.rb index 49f7513193..df335af841 100644 --- a/activesupport/lib/active_support/log_subscriber.rb +++ b/activesupport/lib/active_support/log_subscriber.rb @@ -31,19 +31,6 @@ module ActiveSupport # all logs when the request finishes (via action_dispatch.callback notification) in # a Rails environment. class LogSubscriber - mattr_accessor :colorize_logging - self.colorize_logging = true - - class_attribute :logger - - class << self - remove_method :logger - end - - def self.logger - @logger ||= Rails.logger if defined?(Rails) - end - # Embed in a String to clear all previous ANSI sequences. CLEAR = "\e[0m" BOLD = "\e[1m" @@ -58,32 +45,44 @@ module ActiveSupport CYAN = "\e[36m" WHITE = "\e[37m" - def self.attach_to(namespace, log_subscriber=new, notifier=ActiveSupport::Notifications) - log_subscribers << log_subscriber - @@flushable_loggers = nil + mattr_accessor :colorize_logging + self.colorize_logging = true - log_subscriber.public_methods(false).each do |event| - next if 'call' == event.to_s + class_attribute :logger - notifier.subscribe("#{event}.#{namespace}", log_subscriber) + class << self + remove_method :logger + def logger + @logger ||= Rails.logger if defined?(Rails) end - end - def self.log_subscribers - @@log_subscribers ||= [] - end + def attach_to(namespace, log_subscriber=new, notifier=ActiveSupport::Notifications) + log_subscribers << log_subscriber + @@flushable_loggers = nil - def self.flushable_loggers - @@flushable_loggers ||= begin - loggers = log_subscribers.map(&:logger) - loggers.uniq! - loggers.select { |l| l.respond_to?(:flush) } + log_subscriber.public_methods(false).each do |event| + next if 'call' == event.to_s + + notifier.subscribe("#{event}.#{namespace}", log_subscriber) + end end - end - # Flush all log_subscribers' logger. - def self.flush_all! - flushable_loggers.each(&:flush) + def log_subscribers + @@log_subscribers ||= [] + end + + def flushable_loggers + @@flushable_loggers ||= begin + loggers = log_subscribers.map(&:logger) + loggers.uniq! + loggers.select { |l| l.respond_to?(:flush) } + end + end + + # Flush all log_subscribers' logger. + def flush_all! + flushable_loggers.each(&:flush) + end end def call(message, *args) diff --git a/activesupport/lib/active_support/testing/assertions.rb b/activesupport/lib/active_support/testing/assertions.rb index 8c68f42781..a4e0361a32 100644 --- a/activesupport/lib/active_support/testing/assertions.rb +++ b/activesupport/lib/active_support/testing/assertions.rb @@ -67,15 +67,17 @@ module ActiveSupport # Test if an expression is blank. Passes if object.blank? is true. # # assert_blank [] # => true - def assert_blank(object) - assert object.blank?, "#{object.inspect} is not blank" + def assert_blank(object, message=nil) + message ||= "#{object.inspect} is not blank" + assert object.blank?, message end # Test if an expression is not blank. Passes if object.present? is true. # # assert_present {:data => 'x' } # => true - def assert_present(object) - assert object.present?, "#{object.inspect} is blank" + def assert_present(object, message=nil) + message ||= "#{object.inspect} is blank" + assert object.present?, message end end end |
