From 725090942f698f334b42c332036c571640697a52 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Mon, 12 Jul 2010 09:51:37 +0800 Subject: We shouldn't rely on float comparison, delta added just in case float representation of this values aren't equal --- activesupport/test/notifications_test.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'activesupport') diff --git a/activesupport/test/notifications_test.rb b/activesupport/test/notifications_test.rb index e11de5f67a..3e16e01d89 100644 --- a/activesupport/test/notifications_test.rb +++ b/activesupport/test/notifications_test.rb @@ -198,9 +198,9 @@ module Notifications time = Time.now event = event(:foo, time, time + 0.01, random_id, {}) - assert_equal :foo, event.name - assert_equal time, event.time - assert_equal 10.0, event.duration + assert_equal :foo, event.name + assert_equal time, event.time + assert_in_delta 10.0, event.duration, 0.00000000000001 end def test_events_consumes_information_given_as_payload -- cgit v1.2.3 From 7e075e62479a0eccad6eaf7a7c20f45347860c83 Mon Sep 17 00:00:00 2001 From: Benjamin Quorning Date: Fri, 9 Jul 2010 15:58:58 +0200 Subject: Fixed many references to the old config/environment.rb and Rails::Initializer --- activesupport/lib/active_support/values/time_zone.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/values/time_zone.rb b/activesupport/lib/active_support/values/time_zone.rb index 49dd8a1b99..abd585b64f 100644 --- a/activesupport/lib/active_support/values/time_zone.rb +++ b/activesupport/lib/active_support/values/time_zone.rb @@ -8,10 +8,10 @@ require 'active_support/core_ext/object/try' # * Lazily load TZInfo::Timezone instances only when they're needed. # * Create ActiveSupport::TimeWithZone instances via TimeZone's +local+, +parse+, +at+ and +now+ methods. # -# If you set config.time_zone in the Rails Initializer, you can access this TimeZone object via Time.zone: +# If you set config.time_zone in the Rails Application, you can access this TimeZone object via Time.zone: # -# # environment.rb: -# Rails::Initializer.run do |config| +# # application.rb: +# class Application < Rails::Application # config.time_zone = "Eastern Time (US & Canada)" # end # -- cgit v1.2.3 From 16bae77c568e3e2607ebcfb16a24b9cf6f53df8f Mon Sep 17 00:00:00 2001 From: wycats Date: Tue, 13 Jul 2010 16:13:37 -0700 Subject: Revert "Improve performance of MessageVerifier while keeping it constant time" This reverts commit 8b05c5207dd5757d55d0c384740db289e6bd5415. --- activesupport/lib/active_support/message_verifier.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/message_verifier.rb b/activesupport/lib/active_support/message_verifier.rb index 1031662293..6c46b68eaf 100644 --- a/activesupport/lib/active_support/message_verifier.rb +++ b/activesupport/lib/active_support/message_verifier.rb @@ -47,11 +47,11 @@ module ActiveSupport def secure_compare(a, b) return false unless a.bytesize == b.bytesize - l = a.unpack "C*" + l = a.unpack "C#{a.bytesize}" - res = true - b.each_byte { |byte| res = (byte == l.shift) && res } - res + res = 0 + b.each_byte { |byte| res |= byte ^ l.shift } + res == 0 end def generate_digest(data) -- cgit v1.2.3 From ea7f1fb026a384a2b39362aa179ebfa0ba14a816 Mon Sep 17 00:00:00 2001 From: Nick Sieger Date: Tue, 13 Jul 2010 06:14:26 +0800 Subject: Don't rely on implementation-specific order-dependence of array comparisons in unit tests Signed-off-by: Santiago Pastorino --- activesupport/test/core_ext/class_test.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'activesupport') diff --git a/activesupport/test/core_ext/class_test.rb b/activesupport/test/core_ext/class_test.rb index 08bb13dd35..60ba3b8f88 100644 --- a/activesupport/test/core_ext/class_test.rb +++ b/activesupport/test/core_ext/class_test.rb @@ -1,5 +1,6 @@ require 'abstract_unit' require 'active_support/core_ext/class' +require 'set' class ClassTest < Test::Unit::TestCase class Parent; end @@ -12,16 +13,16 @@ class ClassTest < Test::Unit::TestCase class C < B; end def test_descendants - assert_equal [Foo, Bar, Baz, A, B, C], Parent.descendants - assert_equal [Bar, Baz], Foo.descendants + assert_equal [Foo, Bar, Baz, A, B, C].to_set, Parent.descendants.to_set + assert_equal [Bar, Baz].to_set, Foo.descendants.to_set assert_equal [Baz], Bar.descendants assert_equal [], Baz.descendants end def test_subclasses - assert_equal [Foo, A], Parent.subclasses + assert_equal [Foo, A].to_set, Parent.subclasses.to_set assert_equal [Bar], Foo.subclasses assert_equal [Baz], Bar.subclasses assert_equal [], Baz.subclasses end -end \ No newline at end of file +end -- cgit v1.2.3 From 9c80f5b3910ca0573f6e40aaccf3102c260986b6 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Sat, 17 Jul 2010 13:14:38 -0700 Subject: use === to avoid regular expression creation, and speed up string comparison --- activesupport/lib/active_support/notifications/fanout.rb | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/notifications/fanout.rb b/activesupport/lib/active_support/notifications/fanout.rb index 300ec842a9..b27713e4ad 100644 --- a/activesupport/lib/active_support/notifications/fanout.rb +++ b/activesupport/lib/active_support/notifications/fanout.rb @@ -39,13 +39,7 @@ module ActiveSupport class Binding #:nodoc: def initialize(queue, pattern) @queue = queue - @pattern = - case pattern - when Regexp, NilClass - pattern - else - /^#{Regexp.escape(pattern.to_s)}$/ - end + @pattern = pattern end def subscribe(&block) @@ -70,13 +64,13 @@ module ActiveSupport end def subscribed_to?(name) - !@pattern || @pattern =~ name.to_s + !@pattern || @pattern === name.to_s end def matches?(subscriber_or_name) case subscriber_or_name when String - @pattern && @pattern =~ subscriber_or_name + @pattern && @pattern === subscriber_or_name when self true end -- cgit v1.2.3 From 4226c93779dae53c6921f8ce93d6af000a24e2d1 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Sat, 17 Jul 2010 14:35:44 -0700 Subject: removing Binding class --- .../lib/active_support/notifications/fanout.rb | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/notifications/fanout.rb b/activesupport/lib/active_support/notifications/fanout.rb index b27713e4ad..fa469c8b79 100644 --- a/activesupport/lib/active_support/notifications/fanout.rb +++ b/activesupport/lib/active_support/notifications/fanout.rb @@ -6,13 +6,15 @@ module ActiveSupport def initialize @subscribers = [] @listeners_for = {} + @pattern = nil end def bind(pattern) - Binding.new(self, pattern) + @pattern = pattern + self end - def subscribe(pattern = nil, &block) + def subscribe(pattern = @pattern, &block) @listeners_for.clear @subscribers << Subscriber.new(pattern, &block) @subscribers.last @@ -35,18 +37,6 @@ module ActiveSupport def wait end - # Used for internal implementation only. - class Binding #:nodoc: - def initialize(queue, pattern) - @queue = queue - @pattern = pattern - end - - def subscribe(&block) - @queue.subscribe(@pattern, &block) - end - end - class Subscriber #:nodoc: def initialize(pattern, &block) @pattern = pattern -- cgit v1.2.3 From fa73e777a1dac2daaa14f781b8a17102ca47ea8b Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Sat, 17 Jul 2010 14:44:29 -0700 Subject: private method is not needed --- activesupport/lib/active_support/notifications/fanout.rb | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/notifications/fanout.rb b/activesupport/lib/active_support/notifications/fanout.rb index fa469c8b79..6dfc3c0a99 100644 --- a/activesupport/lib/active_support/notifications/fanout.rb +++ b/activesupport/lib/active_support/notifications/fanout.rb @@ -45,7 +45,7 @@ module ActiveSupport def publish(*args) return unless subscribed_to?(args.first) - push(*args) + @block.call(*args) true end @@ -58,19 +58,9 @@ module ActiveSupport end def matches?(subscriber_or_name) - case subscriber_or_name - when String + self === subscriber_or_name || @pattern && @pattern === subscriber_or_name - when self - true - end end - - private - - def push(*args) - @block.call(*args) - end end end end -- cgit v1.2.3 From 606d8fdfc8b86800fb738854c240c1c15bd272bb Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Sat, 17 Jul 2010 14:45:59 -0700 Subject: drained? is never called --- activesupport/lib/active_support/notifications/fanout.rb | 4 ---- 1 file changed, 4 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/notifications/fanout.rb b/activesupport/lib/active_support/notifications/fanout.rb index 6dfc3c0a99..7eefb7f20a 100644 --- a/activesupport/lib/active_support/notifications/fanout.rb +++ b/activesupport/lib/active_support/notifications/fanout.rb @@ -49,10 +49,6 @@ module ActiveSupport true end - def drained? - true - end - def subscribed_to?(name) !@pattern || @pattern === name.to_s end -- cgit v1.2.3 From cebe5c2fac708885c018550f7ef4610df613e5af Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Sun, 18 Jul 2010 04:55:59 +0800 Subject: It's not needed to initialize the attr when calling mattr_writer --- .../lib/active_support/core_ext/module/attribute_accessors.rb | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/core_ext/module/attribute_accessors.rb b/activesupport/lib/active_support/core_ext/module/attribute_accessors.rb index 9c4d5fae26..2d88cb57e5 100644 --- a/activesupport/lib/active_support/core_ext/module/attribute_accessors.rb +++ b/activesupport/lib/active_support/core_ext/module/attribute_accessors.rb @@ -5,9 +5,7 @@ class Module options = syms.extract_options! syms.each do |sym| class_eval(<<-EOS, __FILE__, __LINE__ + 1) - unless defined? @@#{sym} - @@#{sym} = nil - end + @@#{sym} = nil unless defined? @@#{sym} def self.#{sym} @@#{sym} @@ -28,10 +26,6 @@ class Module options = syms.extract_options! syms.each do |sym| class_eval(<<-EOS, __FILE__, __LINE__ + 1) - unless defined? @@#{sym} - @@#{sym} = nil - end - def self.#{sym}=(obj) @@#{sym} = obj end -- cgit v1.2.3 From cfca55949f51bf3970bae7c506807db97dbcf05f Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Sat, 17 Jul 2010 15:53:22 -0700 Subject: convert duration to an attr_reader --- activesupport/lib/active_support/notifications/instrumenter.rb | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/notifications/instrumenter.rb b/activesupport/lib/active_support/notifications/instrumenter.rb index 7e89402822..34bccb83d0 100644 --- a/activesupport/lib/active_support/notifications/instrumenter.rb +++ b/activesupport/lib/active_support/notifications/instrumenter.rb @@ -33,7 +33,7 @@ module ActiveSupport end class Event - attr_reader :name, :time, :end, :transaction_id, :payload + attr_reader :name, :time, :end, :transaction_id, :payload, :duration def initialize(name, start, ending, transaction_id, payload) @name = name @@ -41,14 +41,11 @@ module ActiveSupport @time = start @transaction_id = transaction_id @end = ending - end - - def duration - @duration ||= 1000.0 * (@end - @time) + @duration = 1000.0 * (@end - @time) end def parent_of?(event) - start = (self.time - event.time) * 1000 + start = (time - event.time) * 1000 start <= 0 && (start + duration >= event.duration) end end -- cgit v1.2.3 From 387036609268c4cf68401a1333715f2ee4aecffc Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Sun, 18 Jul 2010 14:19:34 -0300 Subject: Float comparison adjustment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- activesupport/test/notifications_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport') diff --git a/activesupport/test/notifications_test.rb b/activesupport/test/notifications_test.rb index 3e16e01d89..73c85be87c 100644 --- a/activesupport/test/notifications_test.rb +++ b/activesupport/test/notifications_test.rb @@ -200,7 +200,7 @@ module Notifications assert_equal :foo, event.name assert_equal time, event.time - assert_in_delta 10.0, event.duration, 0.00000000000001 + assert_in_delta 10.0, event.duration, 0.00001 end def test_events_consumes_information_given_as_payload -- cgit v1.2.3 From 2cbef6996c41c785a626291ce29b934797359fd2 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Sun, 18 Jul 2010 15:37:23 -0700 Subject: bind method is not needed, so goodbye! <3 <3 <3 --- activesupport/lib/active_support/notifications.rb | 2 +- activesupport/lib/active_support/notifications/fanout.rb | 8 +------- 2 files changed, 2 insertions(+), 8 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/notifications.rb b/activesupport/lib/active_support/notifications.rb index 1444fc1609..bb5f497c83 100644 --- a/activesupport/lib/active_support/notifications.rb +++ b/activesupport/lib/active_support/notifications.rb @@ -65,7 +65,7 @@ module ActiveSupport end def subscribe(pattern = nil, &block) - @queue.bind(pattern).subscribe(&block) + @queue.subscribe(pattern, &block) end def unsubscribe(subscriber) diff --git a/activesupport/lib/active_support/notifications/fanout.rb b/activesupport/lib/active_support/notifications/fanout.rb index 7eefb7f20a..48ccb156ae 100644 --- a/activesupport/lib/active_support/notifications/fanout.rb +++ b/activesupport/lib/active_support/notifications/fanout.rb @@ -6,15 +6,9 @@ module ActiveSupport def initialize @subscribers = [] @listeners_for = {} - @pattern = nil end - def bind(pattern) - @pattern = pattern - self - end - - def subscribe(pattern = @pattern, &block) + def subscribe(pattern = nil, &block) @listeners_for.clear @subscribers << Subscriber.new(pattern, &block) @subscribers.last -- cgit v1.2.3 From 234b9699463ba435086aa253ee143014a835bbe6 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Sun, 18 Jul 2010 15:39:32 -0700 Subject: tap the subscriber for easier return value --- activesupport/lib/active_support/notifications/fanout.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/notifications/fanout.rb b/activesupport/lib/active_support/notifications/fanout.rb index 48ccb156ae..6e4ff40dc3 100644 --- a/activesupport/lib/active_support/notifications/fanout.rb +++ b/activesupport/lib/active_support/notifications/fanout.rb @@ -10,8 +10,9 @@ module ActiveSupport def subscribe(pattern = nil, &block) @listeners_for.clear - @subscribers << Subscriber.new(pattern, &block) - @subscribers.last + Subscriber.new(pattern, &block).tap do |s| + @subscribers << s + end end def unsubscribe(subscriber) -- cgit v1.2.3 From b2c8a5fd3ea2268022915bb8a7ab449a1502b90d Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Sun, 18 Jul 2010 16:49:29 -0700 Subject: Notifier API == Fanout API, so replace Notifier with Fanout as they quack the same --- .../active_support/log_subscriber/test_helper.rb | 8 ++------ activesupport/lib/active_support/notifications.rb | 24 +--------------------- 2 files changed, 3 insertions(+), 29 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/log_subscriber/test_helper.rb b/activesupport/lib/active_support/log_subscriber/test_helper.rb index 96506a4b2b..a3fb92778b 100644 --- a/activesupport/lib/active_support/log_subscriber/test_helper.rb +++ b/activesupport/lib/active_support/log_subscriber/test_helper.rb @@ -33,7 +33,7 @@ module ActiveSupport module TestHelper def setup @logger = MockLogger.new - @notifier = ActiveSupport::Notifications::Notifier.new(queue) + @notifier = ActiveSupport::Notifications::Fanout.new ActiveSupport::LogSubscriber.colorize_logging = false @@ -81,10 +81,6 @@ module ActiveSupport def set_logger(logger) ActiveSupport::LogSubscriber.logger = logger end - - def queue - ActiveSupport::Notifications::Fanout.new - end end end -end \ No newline at end of file +end diff --git a/activesupport/lib/active_support/notifications.rb b/activesupport/lib/active_support/notifications.rb index bb5f497c83..93d1907edc 100644 --- a/activesupport/lib/active_support/notifications.rb +++ b/activesupport/lib/active_support/notifications.rb @@ -47,34 +47,12 @@ module ActiveSupport delegate :instrument, :to => :instrumenter def notifier - @notifier ||= Notifier.new + @notifier ||= Fanout.new end def instrumenter Thread.current[:"instrumentation_#{notifier.object_id}"] ||= Instrumenter.new(notifier) end end - - class Notifier - def initialize(queue = Fanout.new) - @queue = queue - end - - def publish(*args) - @queue.publish(*args) - end - - def subscribe(pattern = nil, &block) - @queue.subscribe(pattern, &block) - end - - def unsubscribe(subscriber) - @queue.unsubscribe(subscriber) - end - - def wait - @queue.wait - end - end end end -- cgit v1.2.3 From 8cbb89c0bf33e6daad3f91c6debd283b979d800c Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Sun, 18 Jul 2010 17:20:20 -0700 Subject: subscriber does not need to be a block, but an object that responds to #call --- activesupport/lib/active_support/notifications/fanout.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/notifications/fanout.rb b/activesupport/lib/active_support/notifications/fanout.rb index 6e4ff40dc3..3bbb9cca44 100644 --- a/activesupport/lib/active_support/notifications/fanout.rb +++ b/activesupport/lib/active_support/notifications/fanout.rb @@ -8,9 +8,9 @@ module ActiveSupport @listeners_for = {} end - def subscribe(pattern = nil, &block) + def subscribe(pattern = nil, block = Proc.new) @listeners_for.clear - Subscriber.new(pattern, &block).tap do |s| + Subscriber.new(pattern, block).tap do |s| @subscribers << s end end @@ -33,14 +33,14 @@ module ActiveSupport end class Subscriber #:nodoc: - def initialize(pattern, &block) + def initialize(pattern, delegate) @pattern = pattern - @block = block + @delegate = delegate end def publish(*args) return unless subscribed_to?(args.first) - @block.call(*args) + @delegate.call(*args) true end -- cgit v1.2.3 From ad8f4dfc50fe3858b80aeceb6d9240d2af4a2fea Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Sun, 18 Jul 2010 17:37:39 -0700 Subject: avoid proc activation every time a log message is made --- activesupport/lib/active_support/log_subscriber.rb | 23 +++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/log_subscriber.rb b/activesupport/lib/active_support/log_subscriber.rb index 891d718af3..7611aff964 100644 --- a/activesupport/lib/active_support/log_subscriber.rb +++ b/activesupport/lib/active_support/log_subscriber.rb @@ -63,15 +63,9 @@ module ActiveSupport @@flushable_loggers = nil log_subscriber.public_methods(false).each do |event| - notifier.subscribe("#{event}.#{namespace}") do |*args| - next if log_subscriber.logger.nil? - - begin - log_subscriber.send(event, ActiveSupport::Notifications::Event.new(*args)) - rescue Exception => e - log_subscriber.logger.error "Could not log #{args[0].inspect} event. #{e.class}: #{e.message}" - end - end + next if 'call' == event.to_s + + notifier.subscribe("#{event}.#{namespace}", log_subscriber) end end @@ -92,6 +86,17 @@ module ActiveSupport flushable_loggers.each(&:flush) end + def call(message, *args) + return unless logger + + method = message.split('.').first + begin + send(method, ActiveSupport::Notifications::Event.new(message, *args)) + rescue Exception => e + logger.error "Could not log #{message.inspect} event. #{e.class}: #{e.message}" + end + end + protected %w(info debug warn error fatal unknown).each do |level| -- cgit v1.2.3 From fc71d592195b6e04e04cdbb5e640716b0d909e91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Strza=C5=82kowski?= Date: Sat, 17 Jul 2010 17:28:07 +0800 Subject: Introduced redefine_method --- activesupport/lib/active_support/core_ext/module/remove_method.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/core_ext/module/remove_method.rb b/activesupport/lib/active_support/core_ext/module/remove_method.rb index 2714a46b28..b8c01aca0e 100644 --- a/activesupport/lib/active_support/core_ext/module/remove_method.rb +++ b/activesupport/lib/active_support/core_ext/module/remove_method.rb @@ -3,4 +3,9 @@ class Module remove_method(method) rescue NameError end + + def redefine_method(method, &block) + remove_possible_method(method) + define_method(method, &block) + end end \ No newline at end of file -- cgit v1.2.3 From dd4e81df86a119a32d52396c4ef856c856b7965a Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 19 Jul 2010 10:21:45 -0700 Subject: avoid call to Array#first --- activesupport/lib/active_support/notifications/fanout.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/notifications/fanout.rb b/activesupport/lib/active_support/notifications/fanout.rb index 3bbb9cca44..526ca26764 100644 --- a/activesupport/lib/active_support/notifications/fanout.rb +++ b/activesupport/lib/active_support/notifications/fanout.rb @@ -38,9 +38,9 @@ module ActiveSupport @delegate = delegate end - def publish(*args) - return unless subscribed_to?(args.first) - @delegate.call(*args) + def publish(message, *args) + return unless subscribed_to?(message) + @delegate.call(message, *args) true end -- cgit v1.2.3 From 38f0161aabb302550e1522cb62d19e54d448be9b Mon Sep 17 00:00:00 2001 From: Daniel Guettler Date: Sun, 18 Jul 2010 07:30:48 -0400 Subject: Minor performance improvment in notifications/fanout and active_record/log_subscriber [#5098 state:open] --- activesupport/lib/active_support/notifications/fanout.rb | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/notifications/fanout.rb b/activesupport/lib/active_support/notifications/fanout.rb index 526ca26764..64f315cb6a 100644 --- a/activesupport/lib/active_support/notifications/fanout.rb +++ b/activesupport/lib/active_support/notifications/fanout.rb @@ -21,11 +21,11 @@ module ActiveSupport end def publish(name, *args) - if listeners = @listeners_for[name] - listeners.each { |s| s.publish(name, *args) } - else - @listeners_for[name] = @subscribers.select { |s| s.publish(name, *args) } - end + listeners_for(name).each { |s| s.publish(name, *args) } + end + + def listeners_for(name) + @listeners_for[name] ||= @subscribers.select { |s| s.subscribed_to?(name) } end # This is a sync queue, so there is not waiting. @@ -39,9 +39,7 @@ module ActiveSupport end def publish(message, *args) - return unless subscribed_to?(message) @delegate.call(message, *args) - true end def subscribed_to?(name) -- cgit v1.2.3 From 1b26c66ce470ce68674bbdce738c6f68467cff7d Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 19 Jul 2010 13:19:28 -0700 Subject: mocking out debing? call in the MockLogger --- activesupport/lib/active_support/log_subscriber/test_helper.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/log_subscriber/test_helper.rb b/activesupport/lib/active_support/log_subscriber/test_helper.rb index a3fb92778b..0f5fc3554b 100644 --- a/activesupport/lib/active_support/log_subscriber/test_helper.rb +++ b/activesupport/lib/active_support/log_subscriber/test_helper.rb @@ -48,9 +48,12 @@ module ActiveSupport class MockLogger attr_reader :flush_count + attr_accessor :debugging + alias :debug? :debugging def initialize @flush_count = 0 + @debugging = false @logged = Hash.new { |h,k| h[k] = [] } end -- cgit v1.2.3 From 202fb79e8686ee127fe49497c979cfc9c9d985d5 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 19 Jul 2010 13:44:11 -0700 Subject: reusing the time instrumentation from the instrumenter rather than Benchmark. [#5098 state:open] --- .../lib/active_support/notifications/instrumenter.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/notifications/instrumenter.rb b/activesupport/lib/active_support/notifications/instrumenter.rb index 34bccb83d0..ff2b19bc65 100644 --- a/activesupport/lib/active_support/notifications/instrumenter.rb +++ b/activesupport/lib/active_support/notifications/instrumenter.rb @@ -9,23 +9,30 @@ module ActiveSupport def initialize(notifier) @id = unique_id @notifier = notifier + @started = nil + @finished = nil end # Instrument the given block by measuring the time taken to execute it # and publish it. Notice that events get sent even if an error occurs # in the passed-in block def instrument(name, payload={}) - time = Time.now + @started = Time.now begin yield(payload) if block_given? rescue Exception => e payload[:exception] = [e.class.name, e.message] raise e ensure - @notifier.publish(name, time, Time.now, @id, payload) + @finished = Time.now + @notifier.publish(name, @started, @finished, @id, payload) end end + def elapsed + 1000.0 * @finished.to_f - @started.to_f + end + private def unique_id SecureRandom.hex(10) -- cgit v1.2.3 From a6e95ba55401ddcaf9ef867a080b30c2d07c56ac Mon Sep 17 00:00:00 2001 From: Kouhei Sutou Date: Sat, 17 Jul 2010 15:36:40 +0900 Subject: fix mixed encoding logs can't be logged. [#4807 state:committed] Signed-off-by: Kouhei Sutou Signed-off-by: Jeremy Kemper --- activesupport/lib/active_support/buffered_logger.rb | 6 +++++- activesupport/test/buffered_logger_test.rb | 15 +++++++++++++++ activesupport/test/multibyte_test_helpers.rb | 5 ++++- 3 files changed, 24 insertions(+), 2 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/buffered_logger.rb b/activesupport/lib/active_support/buffered_logger.rb index 29c3843d16..b861a6f62a 100644 --- a/activesupport/lib/active_support/buffered_logger.rb +++ b/activesupport/lib/active_support/buffered_logger.rb @@ -101,7 +101,11 @@ module ActiveSupport @guard.synchronize do unless buffer.empty? old_buffer = buffer - @log.write(old_buffer.join) + all_content = StringIO.new + old_buffer.each do |content| + all_content << content + end + @log.write(all_content.string) end # Important to do this even if buffer was empty or else @buffer will diff --git a/activesupport/test/buffered_logger_test.rb b/activesupport/test/buffered_logger_test.rb index 850febb959..97c0ef14db 100644 --- a/activesupport/test/buffered_logger_test.rb +++ b/activesupport/test/buffered_logger_test.rb @@ -1,9 +1,12 @@ require 'abstract_unit' +require 'multibyte_test_helpers' require 'stringio' require 'fileutils' require 'active_support/buffered_logger' class BufferedLoggerTest < Test::Unit::TestCase + include MultibyteTestHelpers + Logger = ActiveSupport::BufferedLogger def setup @@ -146,4 +149,16 @@ class BufferedLoggerTest < Test::Unit::TestCase @logger.expects :clear_buffer @logger.flush end + + def test_buffer_multibyte + @logger.auto_flushing = 2 + @logger.info(UNICODE_STRING) + @logger.info(BYTE_STRING) + assert @output.string.include?(UNICODE_STRING) + byte_string = @output.string.dup + if byte_string.respond_to?(:force_encoding) + byte_string.force_encoding("ASCII-8BIT") + end + assert byte_string.include?(BYTE_STRING) + end end diff --git a/activesupport/test/multibyte_test_helpers.rb b/activesupport/test/multibyte_test_helpers.rb index 597f949059..8839b75601 100644 --- a/activesupport/test/multibyte_test_helpers.rb +++ b/activesupport/test/multibyte_test_helpers.rb @@ -4,6 +4,9 @@ module MultibyteTestHelpers UNICODE_STRING = 'こにちわ' ASCII_STRING = 'ohayo' BYTE_STRING = "\270\236\010\210\245" + if BYTE_STRING.respond_to?(:force_encoding) + BYTE_STRING.force_encoding("ASCII-8BIT") + end def chars(str) ActiveSupport::Multibyte::Chars.new(str) @@ -16,4 +19,4 @@ module MultibyteTestHelpers def assert_equal_codepoints(expected, actual, message=nil) assert_equal(inspect_codepoints(expected), inspect_codepoints(actual), message) end -end \ No newline at end of file +end -- cgit v1.2.3 From 9df9c4bac008ba94c37faff411368c33408faff8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 20 Jul 2010 17:07:18 +0200 Subject: Add a test for elapsed and require missing benchmark file. --- .../active_support/notifications/instrumenter.rb | 4 +-- activesupport/test/notifications_test.rb | 30 ++++++++++------------ 2 files changed, 15 insertions(+), 19 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/notifications/instrumenter.rb b/activesupport/lib/active_support/notifications/instrumenter.rb index ff2b19bc65..e98189f899 100644 --- a/activesupport/lib/active_support/notifications/instrumenter.rb +++ b/activesupport/lib/active_support/notifications/instrumenter.rb @@ -17,8 +17,8 @@ module ActiveSupport # and publish it. Notice that events get sent even if an error occurs # in the passed-in block def instrument(name, payload={}) - @started = Time.now begin + @started = Time.now yield(payload) if block_given? rescue Exception => e payload[:exception] = [e.class.name, e.message] @@ -30,7 +30,7 @@ module ActiveSupport end def elapsed - 1000.0 * @finished.to_f - @started.to_f + 1000.0 * (@finished.to_f - @started.to_f) end private diff --git a/activesupport/test/notifications_test.rb b/activesupport/test/notifications_test.rb index 73c85be87c..41e8ca4ae7 100644 --- a/activesupport/test/notifications_test.rb +++ b/activesupport/test/notifications_test.rb @@ -11,14 +11,11 @@ module Notifications @named_subscription = @notifier.subscribe("named.subscription") { |*args| @named_events << event(*args) } end - private - def event(*args) - ActiveSupport::Notifications::Event.new(*args) - end + private - def drain - @notifier.wait - end + def event(*args) + ActiveSupport::Notifications::Event.new(*args) + end end class UnsubscribeTest < TestCase @@ -132,13 +129,10 @@ module Notifications def test_instrument_returns_block_result assert_equal 2, instrument(:awesome) { 1 + 1 } - drain end def test_instrument_yields_the_paylod_for_further_modification assert_equal 2, instrument(:awesome) { |p| p[:result] = 1 + 1 } - drain - assert_equal 1, @events.size assert_equal :awesome, @events.first.name assert_equal Hash[:result => 2], @events.first.payload @@ -154,15 +148,11 @@ module Notifications 1 + 1 end - drain - assert_equal 1, @events.size assert_equal :wot, @events.first.name assert_equal Hash[:payload => "child"], @events.first.payload end - drain - assert_equal 2, @events.size assert_equal :awesome, @events.last.name assert_equal Hash[:payload => "notifications"], @events.last.payload @@ -177,16 +167,22 @@ module Notifications assert_equal "FAIL", e.message end - drain assert_equal 1, @events.size assert_equal Hash[:payload => "notifications", :exception => ["RuntimeError", "FAIL"]], @events.last.payload end + def test_elapsed + instrument(:something) do + sleep(0.001) + end + + # Elapsed returns duration in ms + assert_in_delta 1, ActiveSupport::Notifications.instrumenter.elapsed, 100 + end + def test_event_is_pushed_even_without_block instrument(:awesome, :payload => "notifications") - drain - assert_equal 1, @events.size assert_equal :awesome, @events.last.name assert_equal Hash[:payload => "notifications"], @events.last.payload -- cgit v1.2.3 From d4151d7f0ac4a0823e788c0beed9ec2476e72386 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 20 Jul 2010 21:20:19 +0200 Subject: Fix a failing test in Railtie and properly define all severity levels in MockLogger for LogSubscriber. --- .../lib/active_support/log_subscriber/test_helper.rb | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/log_subscriber/test_helper.rb b/activesupport/lib/active_support/log_subscriber/test_helper.rb index 0f5fc3554b..9e52cb97a9 100644 --- a/activesupport/lib/active_support/log_subscriber/test_helper.rb +++ b/activesupport/lib/active_support/log_subscriber/test_helper.rb @@ -1,4 +1,5 @@ require 'active_support/log_subscriber' +require 'active_support/buffered_logger' module ActiveSupport class LogSubscriber @@ -47,13 +48,14 @@ module ActiveSupport end class MockLogger + include ActiveSupport::BufferedLogger::Severity + attr_reader :flush_count - attr_accessor :debugging - alias :debug? :debugging + attr_accessor :level - def initialize + def initialize(level = DEBUG) @flush_count = 0 - @debugging = false + @level = level @logged = Hash.new { |h,k| h[k] = [] } end @@ -68,6 +70,14 @@ module ActiveSupport def flush @flush_count += 1 end + + ActiveSupport::BufferedLogger::Severity.constants.each do |severity| + class_eval <<-EOT, __FILE__, __LINE__ + 1 + def #{severity.downcase}? + #{severity} >= @level + end + EOT + end end # Wait notifications to be published. -- cgit v1.2.3 From f1082bd51eb575f22f86b78f347ab75a4b2bff1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 21 Jul 2010 11:56:28 +0200 Subject: Remove old install.rb files. --- activesupport/README | 15 +++------------ activesupport/install.rb | 30 ------------------------------ 2 files changed, 3 insertions(+), 42 deletions(-) delete mode 100644 activesupport/install.rb (limited to 'activesupport') diff --git a/activesupport/README b/activesupport/README index 9fb9a80cbe..aa86f1fd65 100644 --- a/activesupport/README +++ b/activesupport/README @@ -7,22 +7,13 @@ Ruby sweeter. == Download -The latest version of Active Support can be found at +The latest version of Active Support can be installed with Rubygems: -* http://rubyforge.org/project/showfiles.php?group_id=182 +* gem install activesupport Documentation can be found at -* http://as.rubyonrails.com - - -== Installation - -The preferred method of installing Active Support is through its GEM file. You'll need to have -RubyGems[http://rubygems.rubyforge.org/wiki/wiki.pl] installed for that, though. If you have it, -then use: - - % [sudo] gem install activesupport-1.0.0.gem +* http://api.rubyonrails.org == License diff --git a/activesupport/install.rb b/activesupport/install.rb deleted file mode 100644 index 9c54d8c1a9..0000000000 --- a/activesupport/install.rb +++ /dev/null @@ -1,30 +0,0 @@ -require 'rbconfig' -require 'find' -require 'ftools' - -include Config - -# this was adapted from rdoc's install.rb by ways of Log4r - -$sitedir = CONFIG["sitelibdir"] -unless $sitedir - version = CONFIG["MAJOR"] + "." + CONFIG["MINOR"] - $libdir = File.join(CONFIG["libdir"], "ruby", version) - $sitedir = $:.find {|x| x =~ /site_ruby/ } - if !$sitedir - $sitedir = File.join($libdir, "site_ruby") - elsif $sitedir !~ Regexp.quote(version) - $sitedir = File.join($sitedir, version) - end -end - -# the actual gruntwork -Dir.chdir("lib") - -Find.find("active_support", "active_support.rb") { |f| - if f[-3..-1] == ".rb" - File::install(f, File.join($sitedir, *f.split(/\//)), 0644, true) - else - File::makedirs(File.join($sitedir, *f.split(/\//))) - end -} -- cgit v1.2.3 From 508fba9e070e09f0a321f2dd7acf7938967468f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 21 Jul 2010 12:51:14 +0200 Subject: Add .rdoc extension to README files. --- activesupport/README | 34 ---------------------------------- activesupport/README.rdoc | 34 ++++++++++++++++++++++++++++++++++ activesupport/Rakefile | 2 +- 3 files changed, 35 insertions(+), 35 deletions(-) delete mode 100644 activesupport/README create mode 100644 activesupport/README.rdoc (limited to 'activesupport') diff --git a/activesupport/README b/activesupport/README deleted file mode 100644 index aa86f1fd65..0000000000 --- a/activesupport/README +++ /dev/null @@ -1,34 +0,0 @@ -= Active Support -- Utility classes and standard library extensions from Rails - -Active Support is a collection of various utility classes and standard library extensions that were found useful -for Rails. All these additions have hence been collected in this bundle as way to gather all that sugar that makes -Ruby sweeter. - - -== Download - -The latest version of Active Support can be installed with Rubygems: - -* gem install activesupport - -Documentation can be found at - -* http://api.rubyonrails.org - - -== License - -Active Support is released under the MIT license. - - -== Support - -The Active Support homepage is http://www.rubyonrails.com. You can find the Active Support -RubyForge page at http://rubyforge.org/projects/activesupport. And as Jim from Rake says: - - Feel free to submit commits or feature requests. If you send a patch, - remember to update the corresponding unit tests. If fact, I prefer - new feature to be submitted in the form of new unit tests. - -For other information, feel free to ask on the ruby-talk mailing list -(which is mirrored to comp.lang.ruby) or contact mailto:david@loudthinking.com. diff --git a/activesupport/README.rdoc b/activesupport/README.rdoc new file mode 100644 index 0000000000..aa86f1fd65 --- /dev/null +++ b/activesupport/README.rdoc @@ -0,0 +1,34 @@ += Active Support -- Utility classes and standard library extensions from Rails + +Active Support is a collection of various utility classes and standard library extensions that were found useful +for Rails. All these additions have hence been collected in this bundle as way to gather all that sugar that makes +Ruby sweeter. + + +== Download + +The latest version of Active Support can be installed with Rubygems: + +* gem install activesupport + +Documentation can be found at + +* http://api.rubyonrails.org + + +== License + +Active Support is released under the MIT license. + + +== Support + +The Active Support homepage is http://www.rubyonrails.com. You can find the Active Support +RubyForge page at http://rubyforge.org/projects/activesupport. And as Jim from Rake says: + + Feel free to submit commits or feature requests. If you send a patch, + remember to update the corresponding unit tests. If fact, I prefer + new feature to be submitted in the form of new unit tests. + +For other information, feel free to ask on the ruby-talk mailing list +(which is mirrored to comp.lang.ruby) or contact mailto:david@loudthinking.com. diff --git a/activesupport/Rakefile b/activesupport/Rakefile index 2aebe05de2..77b1a8431d 100644 --- a/activesupport/Rakefile +++ b/activesupport/Rakefile @@ -28,7 +28,7 @@ Rake::RDocTask.new { |rdoc| rdoc.options << '--line-numbers' << '--inline-source' rdoc.options << '--charset' << 'utf-8' rdoc.template = ENV['template'] ? "#{ENV['template']}.rb" : '../doc/template/horo' - rdoc.rdoc_files.include('README', 'CHANGELOG') + rdoc.rdoc_files.include('README.rdoc', 'CHANGELOG') rdoc.rdoc_files.include('lib/active_support.rb') rdoc.rdoc_files.include('lib/active_support/**/*.rb') } -- cgit v1.2.3 From d16c5cc99b4ac5a5517b643aabb3b31bf0f0f1b6 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Thu, 22 Jul 2010 01:00:01 +0800 Subject: Change some missing README -> README.rdoc --- activesupport/activesupport.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport') diff --git a/activesupport/activesupport.gemspec b/activesupport/activesupport.gemspec index 8611a1e5fa..df7f68fecf 100644 --- a/activesupport/activesupport.gemspec +++ b/activesupport/activesupport.gemspec @@ -14,7 +14,7 @@ Gem::Specification.new do |s| s.homepage = 'http://www.rubyonrails.org' s.rubyforge_project = 'activesupport' - s.files = Dir['CHANGELOG', 'README', 'lib/**/*'] + s.files = Dir['CHANGELOG', 'README.rdoc', 'lib/**/*'] s.require_path = 'lib' s.has_rdoc = true -- cgit v1.2.3 From 5c858220085dc4ddc1bec496747059dfbe32f1da Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Thu, 22 Jul 2010 05:08:34 +0800 Subject: Hash#to_param is doesn't use sort anymore, some tests added for Hash#to_param --- .../lib/active_support/core_ext/object/to_param.rb | 2 +- activesupport/test/core_ext/hash_ext_test.rb | 25 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/core_ext/object/to_param.rb b/activesupport/lib/active_support/core_ext/object/to_param.rb index 06f077e920..f2e7c2351e 100644 --- a/activesupport/lib/active_support/core_ext/object/to_param.rb +++ b/activesupport/lib/active_support/core_ext/object/to_param.rb @@ -44,6 +44,6 @@ class Hash def to_param(namespace = nil) collect do |key, value| value.to_query(namespace ? "#{namespace}[#{key}]" : key) - end.sort * '&' + end * '&' end end diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb index 7b2c10908f..f369f55675 100644 --- a/activesupport/test/core_ext/hash_ext_test.rb +++ b/activesupport/test/core_ext/hash_ext_test.rb @@ -2,6 +2,8 @@ require 'abstract_unit' require 'active_support/core_ext/hash' require 'bigdecimal' require 'active_support/core_ext/string/access' +require 'active_support/ordered_hash' +require 'active_support/core_ext/object/conversions' class HashExtTest < Test::Unit::TestCase def setup @@ -449,6 +451,29 @@ class IWriteMyOwnXML end end +class HashExtToParamTests < Test::Unit::TestCase + class ToParam < String + def to_param + "#{self}-1" + end + end + + def test_string_hash + assert_equal '', {}.to_param + assert_equal 'hello=world', { :hello => "world" }.to_param + assert_equal 'hello=10', { "hello" => 10 }.to_param + assert_equal 'hello=world&say_bye=true', ActiveSupport::OrderedHash[:hello, "world", "say_bye", true].to_param + end + + def test_number_hash + assert_equal '10=20&30=40&50=60', ActiveSupport::OrderedHash[10, 20, 30, 40, 50, 60].to_param + end + + def test_to_param_hash + assert_equal 'custom=param-1&custom2=param2-1', ActiveSupport::OrderedHash[ToParam.new('custom'), ToParam.new('param'), ToParam.new('custom2'), ToParam.new('param2')].to_param + end +end + class HashToXmlTest < Test::Unit::TestCase def setup @xml_options = { :root => :person, :skip_instruct => true, :indent => 0 } -- cgit v1.2.3 From 6cbd085f692aae7518ac67380e805ebb65896951 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Thu, 22 Jul 2010 06:16:27 +0800 Subject: Test Hash#to_param escapes keys and values [#5175] --- activesupport/test/core_ext/hash_ext_test.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'activesupport') diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb index f369f55675..5d9846a216 100644 --- a/activesupport/test/core_ext/hash_ext_test.rb +++ b/activesupport/test/core_ext/hash_ext_test.rb @@ -472,6 +472,10 @@ class HashExtToParamTests < Test::Unit::TestCase def test_to_param_hash assert_equal 'custom=param-1&custom2=param2-1', ActiveSupport::OrderedHash[ToParam.new('custom'), ToParam.new('param'), ToParam.new('custom2'), ToParam.new('param2')].to_param end + + def test_to_param_hash_escapes_its_keys_and_values + assert_equal 'param+1=A+string+with+%2F+characters+%26+that+should+be+%3F+escaped', { 'param 1' => 'A string with / characters & that should be ? escaped' }.to_param + end end class HashToXmlTest < Test::Unit::TestCase -- cgit v1.2.3 From b456877cfb7e0cb0bab9ffd5674abd23caba0ab4 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Thu, 22 Jul 2010 01:27:02 +0200 Subject: camelize and underscore are sort of inverse of each other, but not in a mathematical sense [#5174 state:resolved] --- activesupport/lib/active_support/inflector/methods.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/inflector/methods.rb b/activesupport/lib/active_support/inflector/methods.rb index b3dc5b2f3a..de49750083 100644 --- a/activesupport/lib/active_support/inflector/methods.rb +++ b/activesupport/lib/active_support/inflector/methods.rb @@ -20,6 +20,11 @@ module ActiveSupport # "active_record".camelize(:lower) # => "activeRecord" # "active_record/errors".camelize # => "ActiveRecord::Errors" # "active_record/errors".camelize(:lower) # => "activeRecord::Errors" + # + # As a rule of thumb you can think of +camelize+ as the inverse of +underscore+, + # though there are cases where that does not hold: + # + # "SSLError".underscore.camelize # => "SslError" def camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true) if first_letter_in_uppercase lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase } @@ -28,13 +33,18 @@ module ActiveSupport end end - # The reverse of +camelize+. Makes an underscored, lowercase form from the expression in the string. + # Makes an underscored, lowercase form from the expression in the string. # # Changes '::' to '/' to convert namespaces to paths. # # Examples: # "ActiveRecord".underscore # => "active_record" # "ActiveRecord::Errors".underscore # => active_record/errors + # + # As a rule of thumb you can think of +underscore+ as the inverse of +camelize+, + # though there are cases where that does not hold: + # + # "SSLError".underscore.camelize # => "SslError" def underscore(camel_cased_word) word = camel_cased_word.to_s.dup word.gsub!(/::/, '/') -- cgit v1.2.3 From 30df88ae06182a72ae7f959dce8d8df4a7adb99a Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Wed, 21 Jul 2010 21:00:11 -0300 Subject: These tests are trusting in the order of the elements so use OrderedHash instead of Hash --- activesupport/test/core_ext/object/to_query_test.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'activesupport') diff --git a/activesupport/test/core_ext/object/to_query_test.rb b/activesupport/test/core_ext/object/to_query_test.rb index 4d655913cc..e28b4cd493 100644 --- a/activesupport/test/core_ext/object/to_query_test.rb +++ b/activesupport/test/core_ext/object/to_query_test.rb @@ -1,4 +1,5 @@ require 'abstract_unit' +require 'active_support/ordered_hash' require 'active_support/core_ext/object/to_query' class ToQueryTest < Test::Unit::TestCase @@ -18,12 +19,12 @@ class ToQueryTest < Test::Unit::TestCase def test_nested_conversion assert_query_equal 'person[login]=seckar&person[name]=Nicholas', - :person => {:name => 'Nicholas', :login => 'seckar'} + :person => ActiveSupport::OrderedHash[:login, 'seckar', :name, 'Nicholas'] end def test_multiple_nested assert_query_equal 'account[person][id]=20&person[id]=10', - :person => {:id => 10}, :account => {:person => {:id => 20}} + ActiveSupport::OrderedHash[:account, {:person => {:id => 20}}, :person, {:id => 10}] end def test_array_values -- cgit v1.2.3 From 89b5e79632c4f0b18099faa846e45741b7c5e700 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Sun, 18 Jul 2010 14:58:40 +0200 Subject: revise download/installation/support sections in READMEs - don't reference ancient gem versions - don't link to old API doc subdomains - point to GitHub instead of RubyForge - point to Lighthouse account for support --- activesupport/README.rdoc | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) (limited to 'activesupport') diff --git a/activesupport/README.rdoc b/activesupport/README.rdoc index aa86f1fd65..77b8a64304 100644 --- a/activesupport/README.rdoc +++ b/activesupport/README.rdoc @@ -1,19 +1,20 @@ -= Active Support -- Utility classes and standard library extensions from Rails += Active Support -- Utility classes and Ruby extensions from Rails -Active Support is a collection of various utility classes and standard library extensions that were found useful -for Rails. All these additions have hence been collected in this bundle as way to gather all that sugar that makes -Ruby sweeter. +Active Support is a collection of utility classes and standard library +extensions that were found useful for the Rails framework. These additions +reside in this package so they can be loaded as needed in Ruby projects +outside of Rails. -== Download +== Download and installation The latest version of Active Support can be installed with Rubygems: -* gem install activesupport + % [sudo] gem install activesupport -Documentation can be found at +Source code can be downloaded as part of the Rails project on GitHub -* http://api.rubyonrails.org +* http://github.com/rails/rails/tree/master/activesupport/ == License @@ -23,12 +24,10 @@ Active Support is released under the MIT license. == Support -The Active Support homepage is http://www.rubyonrails.com. You can find the Active Support -RubyForge page at http://rubyforge.org/projects/activesupport. And as Jim from Rake says: +API documentation is at - Feel free to submit commits or feature requests. If you send a patch, - remember to update the corresponding unit tests. If fact, I prefer - new feature to be submitted in the form of new unit tests. +* http://api.rubyonrails.com -For other information, feel free to ask on the ruby-talk mailing list -(which is mirrored to comp.lang.ruby) or contact mailto:david@loudthinking.com. +Bug reports and feature requests can be filed with the rest for the Ruby on Rails project here: + +* https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets -- cgit v1.2.3 From ba8d89c4c8d1c038c0d6fc9dbfe22f6d528d0da9 Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Wed, 21 Jul 2010 16:29:26 -0700 Subject: Performance optimizations to handle cases of instrumentors that are not listened to. Also, fix a possible concurrency issue. --- activesupport/lib/active_support/notifications.rb | 24 ++++++++++++++++++++-- .../lib/active_support/notifications/fanout.rb | 11 +++++++--- .../active_support/notifications/instrumenter.rb | 2 +- 3 files changed, 31 insertions(+), 6 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/notifications.rb b/activesupport/lib/active_support/notifications.rb index 93d1907edc..886d7183eb 100644 --- a/activesupport/lib/active_support/notifications.rb +++ b/activesupport/lib/active_support/notifications.rb @@ -41,10 +41,30 @@ module ActiveSupport autoload :Event, 'active_support/notifications/instrumenter' autoload :Fanout, 'active_support/notifications/fanout' + @instrumenters = Hash.new { |h,k| h[k] = notifier.listening?(k) } + class << self attr_writer :notifier - delegate :publish, :subscribe, :unsubscribe, :to => :notifier - delegate :instrument, :to => :instrumenter + delegate :publish, :unsubscribe, :to => :notifier + + def instrument(name, payload = {}) + if @instrumenters[name] + instrumenter.instrument(name, payload) { yield payload if block_given? } + else + yield payload if block_given? + end + end + + def subscribe(*args, &block) + notifier.subscribe(*args, &block).tap do + @instrumenters.clear + end + end + + def unsubscribe(*args) + notifier.unsubscribe(*args) + @instrumenters.clear + end def notifier @notifier ||= Fanout.new diff --git a/activesupport/lib/active_support/notifications/fanout.rb b/activesupport/lib/active_support/notifications/fanout.rb index 64f315cb6a..adc34f3286 100644 --- a/activesupport/lib/active_support/notifications/fanout.rb +++ b/activesupport/lib/active_support/notifications/fanout.rb @@ -9,15 +9,16 @@ module ActiveSupport end def subscribe(pattern = nil, block = Proc.new) - @listeners_for.clear - Subscriber.new(pattern, block).tap do |s| + subscriber = Subscriber.new(pattern, block).tap do |s| @subscribers << s end + @listeners_for.clear + subscriber end def unsubscribe(subscriber) - @listeners_for.clear @subscribers.reject! {|s| s.matches?(subscriber)} + @listeners_for.clear end def publish(name, *args) @@ -28,6 +29,10 @@ module ActiveSupport @listeners_for[name] ||= @subscribers.select { |s| s.subscribed_to?(name) } end + def listening?(name) + listeners_for(name).any? + end + # This is a sync queue, so there is not waiting. def wait end diff --git a/activesupport/lib/active_support/notifications/instrumenter.rb b/activesupport/lib/active_support/notifications/instrumenter.rb index e98189f899..713d5a5f25 100644 --- a/activesupport/lib/active_support/notifications/instrumenter.rb +++ b/activesupport/lib/active_support/notifications/instrumenter.rb @@ -19,7 +19,7 @@ module ActiveSupport def instrument(name, payload={}) begin @started = Time.now - yield(payload) if block_given? + yield rescue Exception => e payload[:exception] = [e.class.name, e.message] raise e -- cgit v1.2.3 From 21c4b0942f4014c86117c27a452e68094a05d538 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Thu, 22 Jul 2010 14:57:42 -0300 Subject: Don't shadow outer local variables --- activesupport/lib/active_support/descendants_tracker.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/descendants_tracker.rb b/activesupport/lib/active_support/descendants_tracker.rb index 6cba84d79e..4d1cfacc95 100644 --- a/activesupport/lib/active_support/descendants_tracker.rb +++ b/activesupport/lib/active_support/descendants_tracker.rb @@ -11,9 +11,9 @@ module ActiveSupport end def self.descendants(klass) - @@direct_descendants[klass].inject([]) do |descendants, klass| - descendants << klass - descendants.concat klass.descendants + @@direct_descendants[klass].inject([]) do |descendants, _klass| + descendants << _klass + descendants.concat _klass.descendants end end @@ -40,4 +40,4 @@ module ActiveSupport DescendantsTracker.descendants(self) end end -end \ No newline at end of file +end -- cgit v1.2.3 From b378b19430a4d2ee54cbe7f1935fbd4f8b3b331b Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Thu, 22 Jul 2010 18:56:00 -0300 Subject: Makes Rakefile activate rdoc >= 2.5.9 Signed-off-by: Xavier Noria --- activesupport/Rakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport') diff --git a/activesupport/Rakefile b/activesupport/Rakefile index 77b1a8431d..922e0da236 100644 --- a/activesupport/Rakefile +++ b/activesupport/Rakefile @@ -1,4 +1,4 @@ -gem 'rdoc', '= 2.2' +gem 'rdoc', '>= 2.5.9' require 'rdoc' require 'rake/testtask' require 'rake/rdoctask' -- cgit v1.2.3 From 8f638d8cc17813cbf66682dd998e8f4a505dbcc0 Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Fri, 23 Jul 2010 14:11:14 -0400 Subject: reformatting sentence --- activesupport/lib/active_support/xml_mini.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/xml_mini.rb b/activesupport/lib/active_support/xml_mini.rb index 7594d7b68b..38e20d32da 100644 --- a/activesupport/lib/active_support/xml_mini.rb +++ b/activesupport/lib/active_support/xml_mini.rb @@ -9,7 +9,7 @@ module ActiveSupport module XmlMini extend self - # This module exists to decorate files deserialized using Hash.from_xml with + # This module decorates files deserialized using Hash.from_xml with # the original_filename and content_type methods. module FileLike #:nodoc: attr_writer :original_filename, :content_type -- cgit v1.2.3 From 34165176cfada9f89123dd6580af57ca17c29300 Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Fri, 23 Jul 2010 14:21:03 -0400 Subject: shortening the sentences and removing fluff --- activesupport/lib/active_support/time_with_zone.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/time_with_zone.rb b/activesupport/lib/active_support/time_with_zone.rb index 62d02bdeb6..119c7c0327 100644 --- a/activesupport/lib/active_support/time_with_zone.rb +++ b/activesupport/lib/active_support/time_with_zone.rb @@ -5,9 +5,9 @@ module ActiveSupport # A Time-like class that can represent a time in any time zone. Necessary because standard Ruby Time instances are # limited to UTC and the system's ENV['TZ'] zone. # - # You shouldn't ever need to create a TimeWithZone instance directly via new -- instead, Rails provides the methods - # +local+, +parse+, +at+ and +now+ on TimeZone instances, and +in_time_zone+ on Time and DateTime instances, for a more - # user-friendly syntax. Examples: + # You shouldn't ever need to create a TimeWithZone instance directly via new . Instead use methods + # +local+, +parse+, +at+ and +now+ on TimeZone instances, and +in_time_zone+ on Time and DateTime instances. + # Examples: # # Time.zone = 'Eastern Time (US & Canada)' # => 'Eastern Time (US & Canada)' # Time.zone.local(2007, 2, 10, 15, 30, 45) # => Sat, 10 Feb 2007 15:30:45 EST -05:00 @@ -18,7 +18,8 @@ module ActiveSupport # # See Time and TimeZone for further documentation of these methods. # - # TimeWithZone instances implement the same API as Ruby Time instances, so that Time and TimeWithZone instances are interchangeable. Examples: + # TimeWithZone instances implement the same API as Ruby Time instances, so that Time and TimeWithZone instances are interchangeable. + # Examples: # # t = Time.zone.now # => Sun, 18 May 2008 13:27:25 EDT -04:00 # t.hour # => 13 -- cgit v1.2.3 From 4bf6c1c0c0a9c7a355651868d5c9579e9f98fe6f Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Fri, 23 Jul 2010 14:27:14 -0400 Subject: adding proper markup in comments --- activesupport/lib/active_support/time_with_zone.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/time_with_zone.rb b/activesupport/lib/active_support/time_with_zone.rb index 119c7c0327..ad6c3de1f5 100644 --- a/activesupport/lib/active_support/time_with_zone.rb +++ b/activesupport/lib/active_support/time_with_zone.rb @@ -114,8 +114,8 @@ module ActiveSupport end alias_method :iso8601, :xmlschema - # Coerces the date to a string for JSON encoding. The default format is ISO 8601. You can get - # %Y/%m/%d %H:%M:%S +offset style by setting ActiveSupport::JSON::Encoding.use_standard_json_time_format + # Coerces time to a string for JSON encoding. The default format is ISO 8601. You can get + # %Y/%m/%d %H:%M:%S +offset style by setting ActiveSupport::JSON::Encoding.use_standard_json_time_format # to false. # # ==== Examples -- cgit v1.2.3 From b50635a59f7d2fab2cdba348c4169536fbbb77f4 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 23 Jul 2010 21:11:29 +0200 Subject: update Rakefiles for RDoc 2.5 --- activesupport/Rakefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'activesupport') diff --git a/activesupport/Rakefile b/activesupport/Rakefile index 922e0da236..28426f94ea 100644 --- a/activesupport/Rakefile +++ b/activesupport/Rakefile @@ -1,7 +1,7 @@ gem 'rdoc', '>= 2.5.9' require 'rdoc' require 'rake/testtask' -require 'rake/rdoctask' +require 'rdoc/task' require 'rake/gempackagetask' task :default => :test @@ -22,12 +22,12 @@ dist_dirs = [ "lib", "test"] # Genereate the RDoc documentation -Rake::RDocTask.new { |rdoc| +RDoc::Task.new { |rdoc| rdoc.rdoc_dir = 'doc' rdoc.title = "Active Support -- Utility classes and standard library extensions from Rails" - rdoc.options << '--line-numbers' << '--inline-source' + rdoc.options << '-f' << 'horo' + rdoc.options << '--main' << 'README.rdoc' rdoc.options << '--charset' << 'utf-8' - rdoc.template = ENV['template'] ? "#{ENV['template']}.rb" : '../doc/template/horo' rdoc.rdoc_files.include('README.rdoc', 'CHANGELOG') rdoc.rdoc_files.include('lib/active_support.rb') rdoc.rdoc_files.include('lib/active_support/**/*.rb') -- cgit v1.2.3 From 46c7a991a24db22e1a6c83e55d292c3e3e584714 Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Fri, 23 Jul 2010 16:14:16 -0400 Subject: fixing typo --- activesupport/lib/active_support/log_subscriber.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/log_subscriber.rb b/activesupport/lib/active_support/log_subscriber.rb index 7611aff964..83930b3f0d 100644 --- a/activesupport/lib/active_support/log_subscriber.rb +++ b/activesupport/lib/active_support/log_subscriber.rb @@ -21,7 +21,7 @@ module ActiveSupport # ActiveRecord::LogSubscriber.attach_to :active_record # # Since we need to know all instance methods before attaching the log subscriber, - # the line above shuold be called after your ActiveRecord::LogSubscriber definition. + # the line above should be called after your ActiveRecord::LogSubscriber definition. # # After configured, whenever a "sql.active_record" notification is published, # it will properly dispatch the event (ActiveSupport::Notifications::Event) to -- cgit v1.2.3 From 8429e7b45bc73a44cccae41a21f552c757f93779 Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Fri, 23 Jul 2010 16:22:17 -0400 Subject: making comments sentence more concise --- activesupport/lib/active_support/duration.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/duration.rb b/activesupport/lib/active_support/duration.rb index cd0d66a482..7da357730b 100644 --- a/activesupport/lib/active_support/duration.rb +++ b/activesupport/lib/active_support/duration.rb @@ -4,8 +4,8 @@ require 'active_support/core_ext/object/acts_like' module ActiveSupport # Provides accurate date and time measurements using Date#advance and - # Time#advance, respectively. It mainly supports the methods on Numeric, - # such as in this example: + # Time#advance, respectively. It mainly supports the methods on Numeric. + # Example: # # 1.month.ago # equivalent to Time.now.advance(:months => -1) class Duration < BasicObject -- cgit v1.2.3 From 80cf6559ed0f35cc525c9f2f90cf483033f6dad7 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Fri, 23 Jul 2010 00:28:09 -0300 Subject: Makes restore previosly saved warnings_on_first_load value and avoid warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- activesupport/test/dependencies_test.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'activesupport') diff --git a/activesupport/test/dependencies_test.rb b/activesupport/test/dependencies_test.rb index c7088638c7..4b8c7897b7 100644 --- a/activesupport/test/dependencies_test.rb +++ b/activesupport/test/dependencies_test.rb @@ -117,6 +117,7 @@ class DependenciesTest < Test::Unit::TestCase assert_equal true, $checked_verbose, 'After first load warnings should be left alone.' assert ActiveSupport::Dependencies.loaded.include?(expanded) + ActiveSupport::Dependencies.warnings_on_first_load = old_warnings end end -- cgit v1.2.3 From e1d4e78b15141cf940be7a84ca856425484a98be Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Fri, 23 Jul 2010 00:36:34 -0300 Subject: Removes unused vars 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/kernel/requires.rb | 4 ++-- activesupport/lib/active_support/dependencies.rb | 2 +- activesupport/lib/active_support/json/backends/yaml.rb | 2 +- activesupport/lib/active_support/multibyte/unicode.rb | 11 +++++------ .../lib/active_support/testing/setup_and_teardown.rb | 2 +- activesupport/test/caching_test.rb | 2 +- activesupport/test/core_ext/module_test.rb | 2 +- activesupport/test/dependencies_test.rb | 2 -- activesupport/test/json/encoding_test.rb | 2 +- activesupport/test/memoizable_test.rb | 1 - activesupport/test/multibyte_chars_test.rb | 2 +- activesupport/test/ordered_hash_test.rb | 2 +- activesupport/test/test_test.rb | 2 +- 13 files changed, 16 insertions(+), 20 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/core_ext/kernel/requires.rb b/activesupport/lib/active_support/core_ext/kernel/requires.rb index d2238898d6..3bf46271d7 100644 --- a/activesupport/lib/active_support/core_ext/kernel/requires.rb +++ b/activesupport/lib/active_support/core_ext/kernel/requires.rb @@ -11,13 +11,13 @@ module Kernel # 1. Requiring the module is unsuccessful, maybe it's a gem and nobody required rubygems yet. Try. begin require 'rubygems' - rescue LoadError => rubygems_not_installed + rescue LoadError # => rubygems_not_installed raise cannot_require end # 2. Rubygems is installed and loaded. Try to load the library again begin require library_name - rescue LoadError => gem_not_installed + rescue LoadError # => gem_not_installed raise cannot_require end end diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb index 7d5143ba37..9a6da38b1c 100644 --- a/activesupport/lib/active_support/dependencies.rb +++ b/activesupport/lib/active_support/dependencies.rb @@ -592,7 +592,7 @@ module ActiveSupport #:nodoc: # Convert the provided const desc to a qualified constant name (as a string). # A module, class, symbol, or string may be provided. def to_constant_name(desc) #:nodoc: - name = case desc + case desc when String then desc.sub(/^::/, '') when Symbol then desc.to_s when Module diff --git a/activesupport/lib/active_support/json/backends/yaml.rb b/activesupport/lib/active_support/json/backends/yaml.rb index 215b3d6f90..4cb9d01077 100644 --- a/activesupport/lib/active_support/json/backends/yaml.rb +++ b/activesupport/lib/active_support/json/backends/yaml.rb @@ -13,7 +13,7 @@ module ActiveSupport json = json.read end YAML.load(convert_json_to_yaml(json)) - rescue ArgumentError => e + rescue ArgumentError raise ParseError, "Invalid JSON string" end diff --git a/activesupport/lib/active_support/multibyte/unicode.rb b/activesupport/lib/active_support/multibyte/unicode.rb index 11c72d873b..3d80f5fa58 100644 --- a/activesupport/lib/active_support/multibyte/unicode.rb +++ b/activesupport/lib/active_support/multibyte/unicode.rb @@ -99,15 +99,15 @@ module ActiveSupport current = codepoints[pos] if ( # CR X LF - one = ( previous == database.boundary[:cr] and current == database.boundary[:lf] ) or + ( previous == database.boundary[:cr] and current == database.boundary[:lf] ) or # L X (L|V|LV|LVT) - two = ( database.boundary[:l] === previous and in_char_class?(current, [:l,:v,:lv,:lvt]) ) or + ( database.boundary[:l] === previous and in_char_class?(current, [:l,:v,:lv,:lvt]) ) or # (LV|V) X (V|T) - three = ( in_char_class?(previous, [:lv,:v]) and in_char_class?(current, [:v,:t]) ) or + ( in_char_class?(previous, [:lv,:v]) and in_char_class?(current, [:v,:t]) ) or # (LVT|T) X (T) - four = ( in_char_class?(previous, [:lvt,:t]) and database.boundary[:t] === current ) or + ( in_char_class?(previous, [:lvt,:t]) and database.boundary[:t] === current ) or # X Extend - five = (database.boundary[:extend] === current) + (database.boundary[:extend] === current) ) else unpacked << codepoints[marker..pos-1] @@ -238,7 +238,6 @@ module ActiveSupport bytes.each_index do |i| byte = bytes[i] - is_ascii = byte < 128 is_cont = byte > 127 && byte < 192 is_lead = byte > 191 && byte < 245 is_unused = byte > 240 diff --git a/activesupport/lib/active_support/testing/setup_and_teardown.rb b/activesupport/lib/active_support/testing/setup_and_teardown.rb index d8942c3974..b2d9ddfeb7 100644 --- a/activesupport/lib/active_support/testing/setup_and_teardown.rb +++ b/activesupport/lib/active_support/testing/setup_and_teardown.rb @@ -96,7 +96,7 @@ module ActiveSupport protected def retrieve_mocha_counter(result) #:nodoc: - if using_mocha = respond_to?(:mocha_verify) + if respond_to?(:mocha_verify) # using mocha if defined?(Mocha::TestCaseAdapter::AssertionCounter) Mocha::TestCaseAdapter::AssertionCounter.new(result) else diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb index 3e14c754b7..212c1f82a8 100644 --- a/activesupport/test/caching_test.rb +++ b/activesupport/test/caching_test.rb @@ -279,7 +279,7 @@ module CacheStoreBehavior assert_equal 'bar', @cache.read('foo') raise ArgumentError.new end - rescue ArgumentError => e + rescue ArgumentError end assert_equal "bar", @cache.read('foo') Time.stubs(:now).returns(time + 71) diff --git a/activesupport/test/core_ext/module_test.rb b/activesupport/test/core_ext/module_test.rb index 39ee0ac748..5d9cdf22c2 100644 --- a/activesupport/test/core_ext/module_test.rb +++ b/activesupport/test/core_ext/module_test.rb @@ -147,7 +147,7 @@ class ModuleTest < Test::Unit::TestCase end assert_nothing_raised do - child = Class.new(parent) do + Class.new(parent) do class << self delegate :parent_method, :to => :superclass end diff --git a/activesupport/test/dependencies_test.rb b/activesupport/test/dependencies_test.rb index 4b8c7897b7..d7bde185bd 100644 --- a/activesupport/test/dependencies_test.rb +++ b/activesupport/test/dependencies_test.rb @@ -419,7 +419,6 @@ class DependenciesTest < Test::Unit::TestCase def test_removal_from_tree_should_be_detected with_loading 'dependencies' do - root = ActiveSupport::Dependencies.autoload_paths.first c = ServiceOne ActiveSupport::Dependencies.clear assert ! defined?(ServiceOne) @@ -434,7 +433,6 @@ class DependenciesTest < Test::Unit::TestCase def test_references_should_work with_loading 'dependencies' do - root = ActiveSupport::Dependencies.autoload_paths.first c = ActiveSupport::Dependencies.ref("ServiceOne") service_one_first = ServiceOne assert_equal service_one_first, c.get diff --git a/activesupport/test/json/encoding_test.rb b/activesupport/test/json/encoding_test.rb index a679efb41e..1527d02d16 100644 --- a/activesupport/test/json/encoding_test.rb +++ b/activesupport/test/json/encoding_test.rb @@ -148,7 +148,7 @@ class TestJSONEncoding < Test::Unit::TestCase :latitude => 123.234 } } - result = ActiveSupport::JSON.encode(hash) + ActiveSupport::JSON.encode(hash) end end diff --git a/activesupport/test/memoizable_test.rb b/activesupport/test/memoizable_test.rb index 195e3eaa42..b11fa8d346 100644 --- a/activesupport/test/memoizable_test.rb +++ b/activesupport/test/memoizable_test.rb @@ -134,7 +134,6 @@ class MemoizableTest < ActiveSupport::TestCase end def test_reloadable - counter = @calculator.counter assert_equal 1, @calculator.counter assert_equal 2, @calculator.counter(:reload) assert_equal 2, @calculator.counter diff --git a/activesupport/test/multibyte_chars_test.rb b/activesupport/test/multibyte_chars_test.rb index 78232d8eb5..6ebbfdf334 100644 --- a/activesupport/test/multibyte_chars_test.rb +++ b/activesupport/test/multibyte_chars_test.rb @@ -234,7 +234,7 @@ class MultibyteCharsUTF8BehaviourTest < Test::Unit::TestCase def test_include_raises_when_nil_is_passed @chars.include?(nil) flunk "Expected chars.include?(nil) to raise TypeError or NoMethodError" - rescue Exception => e + rescue Exception end def test_index_should_return_character_offset diff --git a/activesupport/test/ordered_hash_test.rb b/activesupport/test/ordered_hash_test.rb index d340bed444..f47e896487 100644 --- a/activesupport/test/ordered_hash_test.rb +++ b/activesupport/test/ordered_hash_test.rb @@ -214,7 +214,7 @@ class OrderedHashTest < Test::Unit::TestCase def test_alternate_initialization_raises_exception_on_odd_length_args begin - alternate = ActiveSupport::OrderedHash[1,2,3,4,5] + ActiveSupport::OrderedHash[1,2,3,4,5] flunk "Hash::[] should have raised an exception on initialization " + "with an odd number of parameters" rescue diff --git a/activesupport/test/test_test.rb b/activesupport/test/test_test.rb index 3092fe01ae..633d3b212b 100644 --- a/activesupport/test/test_test.rb +++ b/activesupport/test/test_test.rb @@ -49,8 +49,8 @@ class AssertDifferenceTest < ActiveSupport::TestCase end def test_expression_is_evaluated_in_the_appropriate_scope - local_scope = 'foo' silence_warnings do + local_scope = 'foo' assert_difference('local_scope; @object.num') { @object.increment } end end -- cgit v1.2.3 From 8289661903dd1b7fec84e10089f4a04c31965350 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Fri, 23 Jul 2010 00:41:22 -0300 Subject: Make this test, test again MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- activesupport/test/load_paths_test.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'activesupport') diff --git a/activesupport/test/load_paths_test.rb b/activesupport/test/load_paths_test.rb index 9c83d6f061..683ba3dd4e 100644 --- a/activesupport/test/load_paths_test.rb +++ b/activesupport/test/load_paths_test.rb @@ -9,7 +9,6 @@ class LoadPathsTest < Test::Unit::TestCase paths } - # CI has a bunch of duplicate load paths - # assert_equal [], load_paths_count.select { |k, v| v > 1 }, $LOAD_PATH.inspect + assert_equal [], load_paths_count.select { |k, v| v > 1 }, $LOAD_PATH.inspect end end -- cgit v1.2.3 From 85980852a03f8e01c4079e21a429589380cf0d64 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Fri, 23 Jul 2010 00:43:39 -0300 Subject: make a throwaway value equals to _ to avoid warnings 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/hash/conversions.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/core_ext/hash/conversions.rb b/activesupport/lib/active_support/core_ext/hash/conversions.rb index 565c9af7fb..2763af6121 100644 --- a/activesupport/lib/active_support/core_ext/hash/conversions.rb +++ b/activesupport/lib/active_support/core_ext/hash/conversions.rb @@ -83,7 +83,7 @@ class Hash case value.class.to_s when 'Hash' if value['type'] == 'array' - child_key, entries = Array.wrap(value.detect { |k,v| k != 'type' }) # child_key is throwaway + _, entries = Array.wrap(value.detect { |k,v| k != 'type' }) if entries.nil? || (c = value['__content__'] && c.blank?) [] else -- cgit v1.2.3 From 834bd23a07a84ff631da1ded37c643a3a371cb9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 24 Jul 2010 10:22:22 +0200 Subject: Get rid of instrumenter.elapsed. --- .../lib/active_support/notifications/instrumenter.rb | 12 +++--------- activesupport/test/notifications_test.rb | 9 --------- 2 files changed, 3 insertions(+), 18 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/notifications/instrumenter.rb b/activesupport/lib/active_support/notifications/instrumenter.rb index 713d5a5f25..441fefb491 100644 --- a/activesupport/lib/active_support/notifications/instrumenter.rb +++ b/activesupport/lib/active_support/notifications/instrumenter.rb @@ -9,30 +9,24 @@ module ActiveSupport def initialize(notifier) @id = unique_id @notifier = notifier - @started = nil - @finished = nil end # Instrument the given block by measuring the time taken to execute it # and publish it. Notice that events get sent even if an error occurs # in the passed-in block def instrument(name, payload={}) + started = Time.now + begin - @started = Time.now yield rescue Exception => e payload[:exception] = [e.class.name, e.message] raise e ensure - @finished = Time.now - @notifier.publish(name, @started, @finished, @id, payload) + @notifier.publish(name, started, Time.now, @id, payload) end end - def elapsed - 1000.0 * (@finished.to_f - @started.to_f) - end - private def unique_id SecureRandom.hex(10) diff --git a/activesupport/test/notifications_test.rb b/activesupport/test/notifications_test.rb index 41e8ca4ae7..9faa11efbc 100644 --- a/activesupport/test/notifications_test.rb +++ b/activesupport/test/notifications_test.rb @@ -172,15 +172,6 @@ module Notifications :exception => ["RuntimeError", "FAIL"]], @events.last.payload end - def test_elapsed - instrument(:something) do - sleep(0.001) - end - - # Elapsed returns duration in ms - assert_in_delta 1, ActiveSupport::Notifications.instrumenter.elapsed, 100 - end - def test_event_is_pushed_even_without_block instrument(:awesome, :payload => "notifications") assert_equal 1, @events.size -- cgit v1.2.3 From 749948a264ded0aebd77ead087be15d8d5a51ea0 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Sun, 25 Jul 2010 04:17:47 +0800 Subject: Removing one AS/lib ruby and rake adds to $LOAD_PATH --- activesupport/test/load_paths_test.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'activesupport') diff --git a/activesupport/test/load_paths_test.rb b/activesupport/test/load_paths_test.rb index 683ba3dd4e..c8bc1a2ffe 100644 --- a/activesupport/test/load_paths_test.rb +++ b/activesupport/test/load_paths_test.rb @@ -8,6 +8,7 @@ class LoadPathsTest < Test::Unit::TestCase paths[expanded_path] += 1 paths } + load_paths_count[File.expand_path('../../lib', __FILE__)] -= 1 assert_equal [], load_paths_count.select { |k, v| v > 1 }, $LOAD_PATH.inspect end -- cgit v1.2.3 From b1cfcedc8f6dde3b0855fc8fd564e72e730ba5cf Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Sun, 25 Jul 2010 05:21:16 -0300 Subject: Change returning with tap MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- activesupport/lib/active_support/xml_mini/libxml.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/xml_mini/libxml.rb b/activesupport/lib/active_support/xml_mini/libxml.rb index 9cf187302f..7fdcb11465 100644 --- a/activesupport/lib/active_support/xml_mini/libxml.rb +++ b/activesupport/lib/active_support/xml_mini/libxml.rb @@ -1,5 +1,4 @@ require 'libxml' -require 'active_support/core_ext/object/returning' require 'active_support/core_ext/object/blank' # = XmlMini LibXML implementation -- cgit v1.2.3 From b7e0408ca922cf51228818edbfdcd5c63e3cb84e Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Sun, 25 Jul 2010 11:11:23 -0700 Subject: use a hash to collect optional statistics about the instrumentation --- activesupport/lib/active_support/notifications.rb | 16 +++++++++++++--- .../lib/active_support/notifications/instrumenter.rb | 11 +++++++---- activesupport/test/notifications_test.rb | 9 +++++++++ 3 files changed, 29 insertions(+), 7 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/notifications.rb b/activesupport/lib/active_support/notifications.rb index 886d7183eb..d65431a943 100644 --- a/activesupport/lib/active_support/notifications.rb +++ b/activesupport/lib/active_support/notifications.rb @@ -47,11 +47,21 @@ module ActiveSupport attr_writer :notifier delegate :publish, :unsubscribe, :to => :notifier - def instrument(name, payload = {}) + def instrument(name, payload = {}, info = nil) if @instrumenters[name] - instrumenter.instrument(name, payload) { yield payload if block_given? } + instrumenter.instrument(name, payload, info) { + yield payload if block_given? + } else - yield payload if block_given? + value = nil + if block_given? + if info + info[:elapsed] = Benchmark.ms { value = yield payload } + else + value = yield payload + end + end + value end end diff --git a/activesupport/lib/active_support/notifications/instrumenter.rb b/activesupport/lib/active_support/notifications/instrumenter.rb index 441fefb491..4fc446fb2b 100644 --- a/activesupport/lib/active_support/notifications/instrumenter.rb +++ b/activesupport/lib/active_support/notifications/instrumenter.rb @@ -14,16 +14,19 @@ module ActiveSupport # Instrument the given block by measuring the time taken to execute it # and publish it. Notice that events get sent even if an error occurs # in the passed-in block - def instrument(name, payload={}) - started = Time.now - + def instrument(name, payload={}, info = nil) begin + started = Time.now yield rescue Exception => e payload[:exception] = [e.class.name, e.message] raise e ensure - @notifier.publish(name, started, Time.now, @id, payload) + finished = Time.now + if info + info[:elapsed] = 1000.0 * (finished.to_f - started.to_f) + end + @notifier.publish(name, started, finished, @id, payload) end end diff --git a/activesupport/test/notifications_test.rb b/activesupport/test/notifications_test.rb index 9faa11efbc..41e8ca4ae7 100644 --- a/activesupport/test/notifications_test.rb +++ b/activesupport/test/notifications_test.rb @@ -172,6 +172,15 @@ module Notifications :exception => ["RuntimeError", "FAIL"]], @events.last.payload end + def test_elapsed + instrument(:something) do + sleep(0.001) + end + + # Elapsed returns duration in ms + assert_in_delta 1, ActiveSupport::Notifications.instrumenter.elapsed, 100 + end + def test_event_is_pushed_even_without_block instrument(:awesome, :payload => "notifications") assert_equal 1, @events.size -- cgit v1.2.3 From ff0d842454571d78addd1fe9d4f232b600881b1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 25 Jul 2010 20:46:42 +0200 Subject: Revert the previous three commits. * AS::Notifications#instrument should not measure anything, it is not its responsibility; * Adding another argument to AS::Notifications#instrument API needs to be properly discussed; --- activesupport/lib/active_support/notifications.rb | 16 +++------------- .../lib/active_support/notifications/instrumenter.rb | 11 ++++------- activesupport/test/notifications_test.rb | 9 --------- 3 files changed, 7 insertions(+), 29 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/notifications.rb b/activesupport/lib/active_support/notifications.rb index d65431a943..886d7183eb 100644 --- a/activesupport/lib/active_support/notifications.rb +++ b/activesupport/lib/active_support/notifications.rb @@ -47,21 +47,11 @@ module ActiveSupport attr_writer :notifier delegate :publish, :unsubscribe, :to => :notifier - def instrument(name, payload = {}, info = nil) + def instrument(name, payload = {}) if @instrumenters[name] - instrumenter.instrument(name, payload, info) { - yield payload if block_given? - } + instrumenter.instrument(name, payload) { yield payload if block_given? } else - value = nil - if block_given? - if info - info[:elapsed] = Benchmark.ms { value = yield payload } - else - value = yield payload - end - end - value + yield payload if block_given? end end diff --git a/activesupport/lib/active_support/notifications/instrumenter.rb b/activesupport/lib/active_support/notifications/instrumenter.rb index 4fc446fb2b..441fefb491 100644 --- a/activesupport/lib/active_support/notifications/instrumenter.rb +++ b/activesupport/lib/active_support/notifications/instrumenter.rb @@ -14,19 +14,16 @@ module ActiveSupport # Instrument the given block by measuring the time taken to execute it # and publish it. Notice that events get sent even if an error occurs # in the passed-in block - def instrument(name, payload={}, info = nil) + def instrument(name, payload={}) + started = Time.now + begin - started = Time.now yield rescue Exception => e payload[:exception] = [e.class.name, e.message] raise e ensure - finished = Time.now - if info - info[:elapsed] = 1000.0 * (finished.to_f - started.to_f) - end - @notifier.publish(name, started, finished, @id, payload) + @notifier.publish(name, started, Time.now, @id, payload) end end diff --git a/activesupport/test/notifications_test.rb b/activesupport/test/notifications_test.rb index 41e8ca4ae7..9faa11efbc 100644 --- a/activesupport/test/notifications_test.rb +++ b/activesupport/test/notifications_test.rb @@ -172,15 +172,6 @@ module Notifications :exception => ["RuntimeError", "FAIL"]], @events.last.payload end - def test_elapsed - instrument(:something) do - sleep(0.001) - end - - # Elapsed returns duration in ms - assert_in_delta 1, ActiveSupport::Notifications.instrumenter.elapsed, 100 - end - def test_event_is_pushed_even_without_block instrument(:awesome, :payload => "notifications") assert_equal 1, @events.size -- cgit v1.2.3 From b0b9bf320409b66c6c6b680371aca590297cd4cc Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Sun, 25 Jul 2010 18:12:20 -0300 Subject: Object#returning removed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- .../lib/active_support/core_ext/object.rb | 2 -- .../lib/active_support/core_ext/object/misc.rb | 2 -- .../active_support/core_ext/object/returning.rb | 42 ---------------------- activesupport/test/option_merger_test.rb | 2 +- 4 files changed, 1 insertion(+), 47 deletions(-) delete mode 100644 activesupport/lib/active_support/core_ext/object/misc.rb delete mode 100644 activesupport/lib/active_support/core_ext/object/returning.rb (limited to 'activesupport') diff --git a/activesupport/lib/active_support/core_ext/object.rb b/activesupport/lib/active_support/core_ext/object.rb index 27618b55c6..790a26f5c1 100644 --- a/activesupport/lib/active_support/core_ext/object.rb +++ b/activesupport/lib/active_support/core_ext/object.rb @@ -5,9 +5,7 @@ require 'active_support/core_ext/object/try' require 'active_support/core_ext/object/conversions' require 'active_support/core_ext/object/instance_variables' -require 'active_support/core_ext/object/misc' -require 'active_support/core_ext/object/returning' require 'active_support/core_ext/object/to_json' require 'active_support/core_ext/object/to_param' require 'active_support/core_ext/object/to_query' diff --git a/activesupport/lib/active_support/core_ext/object/misc.rb b/activesupport/lib/active_support/core_ext/object/misc.rb deleted file mode 100644 index 3e3af03cc5..0000000000 --- a/activesupport/lib/active_support/core_ext/object/misc.rb +++ /dev/null @@ -1,2 +0,0 @@ -require 'active_support/core_ext/object/returning' -require 'active_support/core_ext/object/with_options' 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 0dc2e1266a..0000000000 --- a/activesupport/lib/active_support/core_ext/object/returning.rb +++ /dev/null @@ -1,42 +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) - yield(value) - value - end -end diff --git a/activesupport/test/option_merger_test.rb b/activesupport/test/option_merger_test.rb index b898292c9c..33e3e69666 100644 --- a/activesupport/test/option_merger_test.rb +++ b/activesupport/test/option_merger_test.rb @@ -1,5 +1,5 @@ require 'abstract_unit' -require 'active_support/core_ext/object/misc' +require 'active_support/core_ext/object/with_options' class OptionMergerTest < Test::Unit::TestCase def setup -- cgit v1.2.3 From 9a32af96d1371a9e0ae2c242b8cbcb64ed2f8c95 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Sun, 25 Jul 2010 18:15:36 -0300 Subject: CHANGELOG updated Object#returning removed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- activesupport/CHANGELOG | 2 ++ 1 file changed, 2 insertions(+) (limited to 'activesupport') diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index 60586cf99a..8706a2aa0b 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -1,5 +1,7 @@ *Rails 3.0.0 [Release Candidate] (unreleased)* +* Removed Object#returning, Object#tap should be used instead. [Santiago Pastorino] + * Deprecation behavior is no longer hardcoded to the name of the environment. Instead, it is set via config.active_support.deprecation and can be one of :log, :stderr or :notify. :notify is a new style that sends the warning -- cgit v1.2.3 From dcb7832ed51b2aeb2ea7386e2f07fcb5d7eb0c6d Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Mon, 26 Jul 2010 00:01:23 +0200 Subject: APIs for individual components are no longer published --- activesupport/Rakefile | 6 ------ 1 file changed, 6 deletions(-) (limited to 'activesupport') diff --git a/activesupport/Rakefile b/activesupport/Rakefile index 28426f94ea..8e2683ef89 100644 --- a/activesupport/Rakefile +++ b/activesupport/Rakefile @@ -45,9 +45,3 @@ task :release => :package do Rake::Gemcutter::Tasks.new(spec).define Rake::Task['gem:push'].invoke end - -desc "Publish the API documentation" -task :pdoc => [:rdoc] do - require 'rake/contrib/sshpublisher' - Rake::SshDirPublisher.new("rails@api.rubyonrails.org", "public_html/as", "doc").upload -end -- cgit v1.2.3 From 53fbbf4b83cb5c2c7fcaa691129fad4df4d266ae Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Sun, 25 Jul 2010 16:01:46 -0700 Subject: fisting warning --- activesupport/lib/active_support/notifications.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/notifications.rb b/activesupport/lib/active_support/notifications.rb index 886d7183eb..ca9f5ae1ac 100644 --- a/activesupport/lib/active_support/notifications.rb +++ b/activesupport/lib/active_support/notifications.rb @@ -45,7 +45,7 @@ module ActiveSupport class << self attr_writer :notifier - delegate :publish, :unsubscribe, :to => :notifier + delegate :publish, :to => :notifier def instrument(name, payload = {}) if @instrumenters[name] -- cgit v1.2.3 From 1b97701e51667e6040b4c576cce9234edef1019e Mon Sep 17 00:00:00 2001 From: wycats Date: Mon, 26 Jul 2010 00:59:54 -0700 Subject: Fix a bug where requires inside of autoloads were being added to the autoloaded_constants list, causing mayhem. [#5165 state:resolved] --- activesupport/lib/active_support/dependencies.rb | 17 +++++--- .../load_path/loaded_constant.rb | 3 ++ .../test/autoloading_fixtures/loads_constant.rb | 4 ++ .../test/autoloading_fixtures/requires_constant.rb | 5 +++ activesupport/test/dependencies_test.rb | 49 ++++++++++++++++++++++ 5 files changed, 73 insertions(+), 5 deletions(-) create mode 100644 activesupport/test/autoloading_fixtures/load_path/loaded_constant.rb create mode 100644 activesupport/test/autoloading_fixtures/loads_constant.rb create mode 100644 activesupport/test/autoloading_fixtures/requires_constant.rb (limited to 'activesupport') diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb index 9a6da38b1c..2b80bd214f 100644 --- a/activesupport/lib/active_support/dependencies.rb +++ b/activesupport/lib/active_support/dependencies.rb @@ -72,10 +72,6 @@ module ActiveSupport #:nodoc: methods.each { |m| class_eval "def #{m}(*) lock { super } end", __FILE__, __LINE__ } end - def get(key) - (val = assoc(key)) ? val[1] : [] - end - locked :concat, :each, :delete_if, :<< def new_constants_for(frames) @@ -85,7 +81,18 @@ module ActiveSupport #:nodoc: next unless mod.is_a?(Module) new_constants = mod.local_constant_names - prior_constants - get(mod_name).concat(new_constants) + + # If we are checking for constants under, say, :Object, nested under something + # else that is checking for constants also under :Object, make sure the + # parent knows that we have found, and taken care of, the constant. + # + # In particular, this means that since Kernel.require discards the constants + # it finds, parents will be notified that about those constants, and not + # consider them "new". As a result, they will not be added to the + # autoloaded_constants list. + each do |key, value| + value.concat(new_constants) if key == mod_name + end new_constants.each do |suffix| constants << ([mod_name, suffix] - ["Object"]).join("::") diff --git a/activesupport/test/autoloading_fixtures/load_path/loaded_constant.rb b/activesupport/test/autoloading_fixtures/load_path/loaded_constant.rb new file mode 100644 index 0000000000..e3d1218c96 --- /dev/null +++ b/activesupport/test/autoloading_fixtures/load_path/loaded_constant.rb @@ -0,0 +1,3 @@ +module LoadedConstant +end + diff --git a/activesupport/test/autoloading_fixtures/loads_constant.rb b/activesupport/test/autoloading_fixtures/loads_constant.rb new file mode 100644 index 0000000000..b5b80c46da --- /dev/null +++ b/activesupport/test/autoloading_fixtures/loads_constant.rb @@ -0,0 +1,4 @@ +module LoadsConstant +end + +RequiresConstant diff --git a/activesupport/test/autoloading_fixtures/requires_constant.rb b/activesupport/test/autoloading_fixtures/requires_constant.rb new file mode 100644 index 0000000000..14804a0de0 --- /dev/null +++ b/activesupport/test/autoloading_fixtures/requires_constant.rb @@ -0,0 +1,5 @@ +require "loaded_constant" + +module RequiresConstant +end + diff --git a/activesupport/test/dependencies_test.rb b/activesupport/test/dependencies_test.rb index d7bde185bd..ec5116bff4 100644 --- a/activesupport/test/dependencies_test.rb +++ b/activesupport/test/dependencies_test.rb @@ -213,6 +213,48 @@ class DependenciesTest < Test::Unit::TestCase end end + def test_doesnt_break_normal_require + path = File.expand_path("../autoloading_fixtures/load_path", __FILE__) + original_path = $:.dup + original_features = $".dup + $:.push(path) + + with_autoloading_fixtures do + RequiresConstant + assert defined?(RequiresConstant) + assert defined?(LoadedConstant) + ActiveSupport::Dependencies.clear + RequiresConstant + assert defined?(RequiresConstant) + assert defined?(LoadedConstant) + end + ensure + remove_constants(:RequiresConstant, :LoadedConstant, :LoadsConstant) + $".replace(original_features) + $:.replace(original_path) + end + + def test_doesnt_break_normal_require_nested + path = File.expand_path("../autoloading_fixtures/load_path", __FILE__) + original_path = $:.dup + original_features = $".dup + $:.push(path) + + with_autoloading_fixtures do + LoadsConstant + assert defined?(LoadsConstant) + assert defined?(LoadedConstant) + ActiveSupport::Dependencies.clear + LoadsConstant + assert defined?(LoadsConstant) + assert defined?(LoadedConstant) + end + ensure + remove_constants(:RequiresConstant, :LoadedConstant, :LoadsConstant) + $".replace(original_features) + $:.replace(original_path) + end + def failing_test_access_thru_and_upwards_fails with_autoloading_fixtures do assert ! defined?(ModuleFolder) @@ -797,4 +839,11 @@ class DependenciesTest < Test::Unit::TestCase ensure ActiveSupport::Dependencies.hook! end + +private + def remove_constants(*constants) + constants.each do |constant| + Object.send(:remove_const, constant) if Object.const_defined?(constant) + end + end end -- cgit v1.2.3 From a5bb1f511f6d4ea63360eefe8c3850f9bbb7505a Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Fri, 23 Jul 2010 15:51:46 -0400 Subject: strengthening the rescue_from test suites MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- activesupport/test/rescuable_test.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'activesupport') diff --git a/activesupport/test/rescuable_test.rb b/activesupport/test/rescuable_test.rb index ff77e16edd..8d2577c64a 100644 --- a/activesupport/test/rescuable_test.rb +++ b/activesupport/test/rescuable_test.rb @@ -14,6 +14,8 @@ class Stargate include ActiveSupport::Rescuable + rescue_from WraithAttack, :with => :sos_first + rescue_from WraithAttack, :with => :sos rescue_from NuclearExplosion do @@ -45,6 +47,11 @@ class Stargate def sos @result = 'killed' end + + def sos_first + @result = 'sos_first' + end + end class RescueableTest < Test::Unit::TestCase @@ -66,4 +73,11 @@ class RescueableTest < Test::Unit::TestCase @stargate.dispatch :ronanize assert_equal 'dex', @stargate.result end + + def test_rescues_defined_later_are_added_at_end_of_the_rescue_handlers_array + expected = ["WraithAttack", "WraithAttack", "NuclearExplosion", "MadRonon"] + result = @stargate.send(:rescue_handlers).collect {|e| e.first} + assert_equal expected, result + end + end -- cgit v1.2.3 From 78c8242d2f92bccc4caedc235b8cfbcfcb3650cf Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Mon, 26 Jul 2010 09:41:53 -0400 Subject: strengthening the test suite for rescue_from MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- activesupport/test/rescuable_test.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'activesupport') diff --git a/activesupport/test/rescuable_test.rb b/activesupport/test/rescuable_test.rb index 8d2577c64a..1c74ce8b2a 100644 --- a/activesupport/test/rescuable_test.rb +++ b/activesupport/test/rescuable_test.rb @@ -9,6 +9,9 @@ end class MadRonon < StandardError end +class CoolError < StandardError +end + class Stargate attr_accessor :result @@ -54,9 +57,23 @@ class Stargate end +class CoolStargate < Stargate + attr_accessor :result + + include ActiveSupport::Rescuable + + rescue_from CoolError, :with => :sos_cool_error + + def sos_cool_error + @result = 'sos_cool_error' + end +end + + class RescueableTest < Test::Unit::TestCase def setup @stargate = Stargate.new + @cool_stargate = CoolStargate.new end def test_rescue_from_with_method @@ -80,4 +97,10 @@ class RescueableTest < Test::Unit::TestCase assert_equal expected, result end + def test_children_should_inherit_rescue_defintions_from_parents_and_child_rescue_should_be_appended + expected = ["WraithAttack", "WraithAttack", "NuclearExplosion", "MadRonon", "CoolError"] + result = @cool_stargate.send(:rescue_handlers).collect {|e| e.first} + assert_equal expected, result + end + end -- cgit v1.2.3 From 4ea1753fc2bcbaca0a50073463ef4b020a2e3c5f Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Mon, 26 Jul 2010 12:42:07 -0300 Subject: This is for making sure const_missing is triggered without warnings --- activesupport/test/autoloading_fixtures/loads_constant.rb | 3 ++- activesupport/test/dependencies_test.rb | 10 ++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) (limited to 'activesupport') diff --git a/activesupport/test/autoloading_fixtures/loads_constant.rb b/activesupport/test/autoloading_fixtures/loads_constant.rb index b5b80c46da..0b30dc8bca 100644 --- a/activesupport/test/autoloading_fixtures/loads_constant.rb +++ b/activesupport/test/autoloading_fixtures/loads_constant.rb @@ -1,4 +1,5 @@ module LoadsConstant end -RequiresConstant +# The _ = assignment is to prevent warnings +_ = RequiresConstant diff --git a/activesupport/test/dependencies_test.rb b/activesupport/test/dependencies_test.rb index ec5116bff4..f98d823f00 100644 --- a/activesupport/test/dependencies_test.rb +++ b/activesupport/test/dependencies_test.rb @@ -220,11 +220,12 @@ class DependenciesTest < Test::Unit::TestCase $:.push(path) with_autoloading_fixtures do - RequiresConstant + # The _ = assignments are to prevent warnings + _ = RequiresConstant assert defined?(RequiresConstant) assert defined?(LoadedConstant) ActiveSupport::Dependencies.clear - RequiresConstant + _ = RequiresConstant assert defined?(RequiresConstant) assert defined?(LoadedConstant) end @@ -241,11 +242,12 @@ class DependenciesTest < Test::Unit::TestCase $:.push(path) with_autoloading_fixtures do - LoadsConstant + # The _ = assignments are to prevent warnings + _ = LoadsConstant assert defined?(LoadsConstant) assert defined?(LoadedConstant) ActiveSupport::Dependencies.clear - LoadsConstant + _ = LoadsConstant assert defined?(LoadsConstant) assert defined?(LoadedConstant) end -- cgit v1.2.3 From e87e3db200e5b711237da8bcdc873044a984ad90 Mon Sep 17 00:00:00 2001 From: Bernerd Schaefer Date: Sat, 17 Jul 2010 16:45:19 -0500 Subject: XmlMini.rename_key emits valid xml with dasherize This resolves issues for libraries which use '_' prefixed keys in their attributes hash, such as Mongoid. A key like "_id" or "_type" will no longer be converted to "<-id>" and "<-type>". Signed-off-by: wycats --- activesupport/lib/active_support/xml_mini.rb | 6 +++- activesupport/test/test_xml_mini.rb | 49 ++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 activesupport/test/test_xml_mini.rb (limited to 'activesupport') diff --git a/activesupport/lib/active_support/xml_mini.rb b/activesupport/lib/active_support/xml_mini.rb index 38e20d32da..352172027b 100644 --- a/activesupport/lib/active_support/xml_mini.rb +++ b/activesupport/lib/active_support/xml_mini.rb @@ -129,12 +129,16 @@ module ActiveSupport camelize = options.has_key?(:camelize) && options[:camelize] dasherize = !options.has_key?(:dasherize) || options[:dasherize] key = key.camelize if camelize - key = key.dasherize if dasherize + key = _dasherize(key) if dasherize key end protected + def _dasherize(key) + key.gsub(/(?!^[_]*)_(?![_]*$)/, '-') + end + # TODO: Add support for other encodings def _parse_binary(bin, entity) #:nodoc: case entity['encoding'] diff --git a/activesupport/test/test_xml_mini.rb b/activesupport/test/test_xml_mini.rb new file mode 100644 index 0000000000..585eb15c6e --- /dev/null +++ b/activesupport/test/test_xml_mini.rb @@ -0,0 +1,49 @@ +require 'abstract_unit' +require 'active_support/xml_mini' + +class XmlMiniTest < Test::Unit::TestCase + def test_rename_key_dasherizes_by_default + assert_equal "my-key", ActiveSupport::XmlMini.rename_key("my_key") + end + + def test_rename_key_does_nothing_with_dasherize_true + assert_equal "my-key", ActiveSupport::XmlMini.rename_key("my_key", :dasherize => true) + end + + def test_rename_key_does_nothing_with_dasherize_false + assert_equal "my_key", ActiveSupport::XmlMini.rename_key("my_key", :dasherize => false) + end + + def test_rename_key_camelizes_with_camelize_true + assert_equal "MyKey", ActiveSupport::XmlMini.rename_key("my_key", :camelize => true) + end + + def test_rename_key_camelizes_with_camelize_true + assert_equal "MyKey", ActiveSupport::XmlMini.rename_key("my_key", :camelize => true) + end + + def test_rename_key_does_not_dasherize_leading_underscores + assert_equal "_id", ActiveSupport::XmlMini.rename_key("_id") + end + + def test_rename_key_with_leading_underscore_dasherizes_interior_underscores + assert_equal "_my-key", ActiveSupport::XmlMini.rename_key("_my_key") + end + + def test_rename_key_does_not_dasherize_trailing_underscores + assert_equal "id_", ActiveSupport::XmlMini.rename_key("id_") + end + + def test_rename_key_with_trailing_underscore_dasherizes_interior_underscores + assert_equal "my-key_", ActiveSupport::XmlMini.rename_key("my_key_") + end + + def test_rename_key_does_not_dasherize_multiple_leading_underscores + assert_equal "__id", ActiveSupport::XmlMini.rename_key("__id") + end + + def test_rename_key_does_not_dasherize_multiple_leading_underscores + assert_equal "id__", ActiveSupport::XmlMini.rename_key("id__") + end + +end -- cgit v1.2.3 From e56c9ef08db49653f0c63a0305d563b2514b266b Mon Sep 17 00:00:00 2001 From: Leigh Caplan Date: Wed, 21 Jul 2010 16:46:38 -0700 Subject: Override new on proxy objects so that they never wrap nil or false. --- activesupport/lib/active_support/deprecation/proxy_wrappers.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/deprecation/proxy_wrappers.rb b/activesupport/lib/active_support/deprecation/proxy_wrappers.rb index dec56715be..b22d0a6941 100644 --- a/activesupport/lib/active_support/deprecation/proxy_wrappers.rb +++ b/activesupport/lib/active_support/deprecation/proxy_wrappers.rb @@ -3,6 +3,13 @@ require 'active_support/inflector' module ActiveSupport module Deprecation class DeprecationProxy #:nodoc: + def self.new(*args, &block) + object = args.first + + return object unless object + super + end + instance_methods.each { |m| undef_method m unless m =~ /^__|^object_id$/ } # Don't give a deprecation warning on inspect since test/unit and error -- cgit v1.2.3 From 37d82f2ca0f8e81d473969586e70826f27538072 Mon Sep 17 00:00:00 2001 From: Leigh Caplan Date: Wed, 21 Jul 2010 16:51:15 -0700 Subject: Test to ensure that falsy objects aren't wrapped by deprecation proxies --- .../test/deprecation/proxy_wrappers_test.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 activesupport/test/deprecation/proxy_wrappers_test.rb (limited to 'activesupport') diff --git a/activesupport/test/deprecation/proxy_wrappers_test.rb b/activesupport/test/deprecation/proxy_wrappers_test.rb new file mode 100644 index 0000000000..c507eff38e --- /dev/null +++ b/activesupport/test/deprecation/proxy_wrappers_test.rb @@ -0,0 +1,22 @@ +require 'abstract_unit' +require 'active_support/deprecation' + +class ProxyWrappersTest < Test::Unit::TestCase + Waffles = false + NewWaffles = :hamburgers + + def test_deprecated_object_proxy_doesnt_wrap_falsy_objects + proxy = ActiveSupport::Deprecation::DeprecatedObjectProxy.new(nil, "message") + assert !proxy + end + + def test_deprecated_instance_variable_proxy_doesnt_wrap_falsy_objects + proxy = ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy.new(nil, :waffles) + assert !proxy + end + + def test_deprecated_constant_proxy_doesnt_wrap_falsy_objects + proxy = ActiveSupport::Deprecation::DeprecatedConstantProxy.new(Waffles, NewWaffles) + assert !proxy + end +end \ No newline at end of file -- cgit v1.2.3 From 32844cbc025b394ecd0b9fe2fd755b4e5b6cd4e7 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 26 Jul 2010 09:57:29 -0700 Subject: fixing space errors --- activesupport/lib/active_support/deprecation/proxy_wrappers.rb | 4 ++-- activesupport/test/deprecation/proxy_wrappers_test.rb | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/deprecation/proxy_wrappers.rb b/activesupport/lib/active_support/deprecation/proxy_wrappers.rb index b22d0a6941..deb33ab702 100644 --- a/activesupport/lib/active_support/deprecation/proxy_wrappers.rb +++ b/activesupport/lib/active_support/deprecation/proxy_wrappers.rb @@ -5,11 +5,11 @@ module ActiveSupport class DeprecationProxy #:nodoc: def self.new(*args, &block) object = args.first - + return object unless object super end - + instance_methods.each { |m| undef_method m unless m =~ /^__|^object_id$/ } # Don't give a deprecation warning on inspect since test/unit and error diff --git a/activesupport/test/deprecation/proxy_wrappers_test.rb b/activesupport/test/deprecation/proxy_wrappers_test.rb index c507eff38e..aa887f274d 100644 --- a/activesupport/test/deprecation/proxy_wrappers_test.rb +++ b/activesupport/test/deprecation/proxy_wrappers_test.rb @@ -4,19 +4,19 @@ require 'active_support/deprecation' class ProxyWrappersTest < Test::Unit::TestCase Waffles = false NewWaffles = :hamburgers - + def test_deprecated_object_proxy_doesnt_wrap_falsy_objects proxy = ActiveSupport::Deprecation::DeprecatedObjectProxy.new(nil, "message") assert !proxy end - + def test_deprecated_instance_variable_proxy_doesnt_wrap_falsy_objects proxy = ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy.new(nil, :waffles) assert !proxy end - + def test_deprecated_constant_proxy_doesnt_wrap_falsy_objects proxy = ActiveSupport::Deprecation::DeprecatedConstantProxy.new(Waffles, NewWaffles) assert !proxy end -end \ No newline at end of file +end -- cgit v1.2.3 From 856fc4bbc379b330d11702adbc2b26850dca6206 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Mon, 26 Jul 2010 12:52:34 -0500 Subject: Prep for RC --- activesupport/CHANGELOG | 2 +- activesupport/lib/active_support/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'activesupport') diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index 8706a2aa0b..8485e7d46b 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -1,4 +1,4 @@ -*Rails 3.0.0 [Release Candidate] (unreleased)* +*Rails 3.0.0 [release candidate] (July 26th, 2010)* * Removed Object#returning, Object#tap should be used instead. [Santiago Pastorino] diff --git a/activesupport/lib/active_support/version.rb b/activesupport/lib/active_support/version.rb index 52612c27cb..9d2cf13260 100644 --- a/activesupport/lib/active_support/version.rb +++ b/activesupport/lib/active_support/version.rb @@ -3,7 +3,7 @@ module ActiveSupport MAJOR = 3 MINOR = 0 TINY = 0 - BUILD = "beta4" + BUILD = "rc" STRING = [MAJOR, MINOR, TINY, BUILD].join('.') end -- cgit v1.2.3 From a2ca9cb78d6117a34671842cd76d20279d24c0ff Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Mon, 26 Jul 2010 20:09:34 -0300 Subject: This is a hash in 1.9.2 --- activesupport/test/load_paths_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport') diff --git a/activesupport/test/load_paths_test.rb b/activesupport/test/load_paths_test.rb index c8bc1a2ffe..36e3726a02 100644 --- a/activesupport/test/load_paths_test.rb +++ b/activesupport/test/load_paths_test.rb @@ -10,6 +10,6 @@ class LoadPathsTest < Test::Unit::TestCase } load_paths_count[File.expand_path('../../lib', __FILE__)] -= 1 - assert_equal [], load_paths_count.select { |k, v| v > 1 }, $LOAD_PATH.inspect + assert load_paths_count.select { |k, v| v > 1 }.empty?, $LOAD_PATH.inspect end end -- cgit v1.2.3 From b357aedbf655976590fba4547dbe3edaf5cc8288 Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Mon, 26 Jul 2010 22:41:13 -0400 Subject: making comments have a consistent theme of narrative --- activesupport/lib/active_support/cache.rb | 48 ++++++++++++++----------------- 1 file changed, 22 insertions(+), 26 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/cache.rb b/activesupport/lib/active_support/cache.rb index bef9c98ecf..1445cec446 100644 --- a/activesupport/lib/active_support/cache.rb +++ b/activesupport/lib/active_support/cache.rb @@ -175,7 +175,7 @@ module ActiveSupport @silence = previous_silence end - # Set to true if cache stores should be instrumented. By default is false. + # Set to true if cache stores should be instrumented. Default is false. def self.instrument=(boolean) Thread.current[:instrument_cache_store] = boolean end @@ -187,7 +187,7 @@ module ActiveSupport # Fetches data from the cache, using the given key. If there is data in # the cache with the given key, then that data is returned. # - # If there is no such data in the cache (a cache miss occurred), then + # If there is no such data in the cache (a cache miss occurred), # then nil will be returned. However, if a block has been passed, then # that block will be run in the event of a cache miss. The return value # of the block will be written to the cache under the given cache key, @@ -353,11 +353,9 @@ module ActiveSupport results end - # Writes the given value to the cache, with the given key. + # Writes the value to the cache, with the key. # - # You may also specify additional options via the +options+ argument. - # The specific cache store implementation will decide what to do with - # +options+. + # Options are passed to the underlying cache implementation. def write(name, value, options = nil) options = merged_options(options) instrument(:write, name, options) do |payload| @@ -366,7 +364,7 @@ module ActiveSupport end end - # Delete an entry in the cache. Returns +true+ if there was an entry to delete. + # Deletes an entry in the cache. Returns +true+ if an entry is deleted. # # Options are passed to the underlying cache implementation. def delete(name, options = nil) @@ -376,7 +374,7 @@ module ActiveSupport end end - # Return true if the cache contains an entry with this name. + # Return true if the cache contains an entry for the given key. # # Options are passed to the underlying cache implementation. def exist?(name, options = nil) @@ -391,11 +389,11 @@ module ActiveSupport end end - # Delete all entries whose keys match a pattern. + # Delete all entries with keys matching the pattern. # # Options are passed to the underlying cache implementation. # - # Not all implementations may support +delete_matched+. + # All implementations may not support this method. def delete_matched(matcher, options = nil) raise NotImplementedError.new("#{self.class.name} does not support delete_matched") end @@ -404,7 +402,7 @@ module ActiveSupport # # Options are passed to the underlying cache implementation. # - # Not all implementations may support +delete_matched+. + # All implementations may not support this method. def increment(name, amount = 1, options = nil) raise NotImplementedError.new("#{self.class.name} does not support increment") end @@ -413,28 +411,26 @@ module ActiveSupport # # Options are passed to the underlying cache implementation. # - # Not all implementations may support +delete_matched+. + # All implementations may not support this method. def decrement(name, amount = 1, options = nil) raise NotImplementedError.new("#{self.class.name} does not support decrement") end - # Cleanup the cache by removing expired entries. Not all cache implementations may - # support this method. + # Cleanup the cache by removing expired entries. # # Options are passed to the underlying cache implementation. # - # Not all implementations may support +delete_matched+. + # All implementations may not support this method. def cleanup(options = nil) raise NotImplementedError.new("#{self.class.name} does not support cleanup") end - # Clear the entire cache. Not all cache implementations may support this method. - # You should be careful with this method since it could affect other processes - # if you are using a shared cache. + # Clear the entire cache. Be careful with this method since it could + # affect other processes if shared cache is being used. # # Options are passed to the underlying cache implementation. # - # Not all implementations may support +delete_matched+. + # All implementations may not support this method. def clear(options = nil) raise NotImplementedError.new("#{self.class.name} does not support clear") end @@ -483,9 +479,9 @@ module ActiveSupport end end - # Expand a key to be a consistent string value. If the object responds to +cache_key+, - # it will be called. Otherwise, the to_param method will be called. If the key is a - # Hash, the keys will be sorted alphabetically. + # Expand key to be a consistent string value. Invoke +cache_key+ if + # object responds to +cache_key+. Otherwise, to_param method will be + # called. If the key is a Hash, then keys will be sorted alphabetically. def expanded_key(key) # :nodoc: if key.respond_to?(:cache_key) key = key.cache_key.to_s @@ -502,7 +498,7 @@ module ActiveSupport end end - # Prefix a key with the namespace. The two values will be delimited with a colon. + # Prefix a key with the namespace. Namespace and key will be delimited with a colon. def namespaced_key(key, options) key = expanded_key(key) namespace = options[:namespace] if options @@ -599,7 +595,7 @@ module ActiveSupport end end - # Set a new time to live on the entry so it expires at the given time. + # Set a new time when the entry will expire. def expires_at=(time) if time @expires_in = time.to_f - @created_at @@ -608,12 +604,12 @@ module ActiveSupport end end - # Seconds since the epoch when the cache entry will expire. + # Seconds since the epoch when the entry will expire. def expires_at @expires_in ? @created_at + @expires_in : nil end - # Get the size of the cached value. This could be less than value.size + # Returns the size of the cached value. This could be less than value.size # if the data is compressed. def size if @value.nil? -- cgit v1.2.3 From d2149256252cabae6d49852bb5765877c59f8f5c Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Mon, 26 Jul 2010 23:03:46 -0400 Subject: making comments meaningful by correcting, adding and pruning --- activesupport/lib/active_support/cache/mem_cache_store.rb | 7 +++---- activesupport/lib/active_support/cache/memory_store.rb | 10 +++++----- activesupport/lib/active_support/cache/strategy/local_cache.rb | 10 +++++----- 3 files changed, 13 insertions(+), 14 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/cache/mem_cache_store.rb b/activesupport/lib/active_support/cache/mem_cache_store.rb index 852defeae8..f32b562368 100644 --- a/activesupport/lib/active_support/cache/mem_cache_store.rb +++ b/activesupport/lib/active_support/cache/mem_cache_store.rb @@ -16,8 +16,7 @@ module ActiveSupport # Special features: # - Clustering and load balancing. One can specify multiple memcached servers, # and MemCacheStore will load balance between all available servers. If a - # server goes down, then MemCacheStore will ignore it until it goes back - # online. + # server goes down, then MemCacheStore will ignore it until it comes back up. # # MemCacheStore implements the Strategy::LocalCache strategy which implements # an in memory cache inside of a block. @@ -69,7 +68,7 @@ module ActiveSupport extend LocalCacheWithRaw end - # Reads multiple keys from the cache using a single call to the + # Reads multiple values from the cache using a single call to the # servers for all keys. Options can be passed in the last argument. def read_multi(*names) options = names.extract_options! @@ -113,7 +112,7 @@ module ActiveSupport end # Clear the entire cache on all memcached servers. This method should - # be used with care when using a shared cache. + # be used with care when shared cache is being used. def clear(options = nil) @data.flush_all end diff --git a/activesupport/lib/active_support/cache/memory_store.rb b/activesupport/lib/active_support/cache/memory_store.rb index f5c2b8af8b..b15bb42c88 100644 --- a/activesupport/lib/active_support/cache/memory_store.rb +++ b/activesupport/lib/active_support/cache/memory_store.rb @@ -5,9 +5,9 @@ module ActiveSupport # A cache store implementation which stores everything into memory in the # same process. If you're running multiple Ruby on Rails server processes # (which is the case if you're using mongrel_cluster or Phusion Passenger), - # then this means that your Rails server process instances won't be able + # then this means that Rails server process instances won't be able # to share cache data with each other and this may not be the most - # appropriate cache for you. + # appropriate cache in that scenario. # # This cache has a bounded size specified by the :size options to the # initializer (default is 32Mb). When the cache exceeds the allotted size, @@ -47,8 +47,8 @@ module ActiveSupport end end - # Prune the cache down so the entries fit within the specified memory size by removing - # the least recently accessed entries. + # To ensure entries fit within the specified memory prune the cache by removing the least + # recently accessed entries. def prune(target_size, max_time = nil) return if pruning? @pruning = true @@ -67,7 +67,7 @@ module ActiveSupport end end - # Return true if the cache is currently be pruned to remove older entries. + # Returns true if the cache is currently being pruned. def pruning? @pruning end diff --git a/activesupport/lib/active_support/cache/strategy/local_cache.rb b/activesupport/lib/active_support/cache/strategy/local_cache.rb index efb5ad26ab..3edba52fc4 100644 --- a/activesupport/lib/active_support/cache/strategy/local_cache.rb +++ b/activesupport/lib/active_support/cache/strategy/local_cache.rb @@ -8,7 +8,7 @@ module ActiveSupport # duration of a block. Repeated calls to the cache for the same key will hit the # in memory cache for faster access. module LocalCache - # Simple memory backed cache. This cache is not thread safe but is intended only + # Simple memory backed cache. This cache is not thread safe and is intended only # for serving as a temporary memory cache for a single thread. class LocalStore < Store def initialize @@ -16,7 +16,7 @@ module ActiveSupport @data = {} end - # Since it isn't thread safe, don't allow synchronizing. + # Don't allow synchronizing since it isn't thread safe, def synchronize # :nodoc: yield end @@ -39,7 +39,7 @@ module ActiveSupport end end - # Use a local cache to front for the cache for the duration of a block. + # Use a local cache for the duration of block. def with_local_cache save_val = Thread.current[thread_local_key] begin @@ -50,8 +50,8 @@ module ActiveSupport end end - # Middleware class can be inserted as a Rack handler to use a local cache for the - # duration of a request. + # Middleware class can be inserted as a Rack handler to be local cache for the + # duration of request. def middleware @middleware ||= begin klass = Class.new -- cgit v1.2.3 From f3409dc0a0b7f0ce009825f8df806b391ff770ec Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Mon, 26 Jul 2010 23:35:15 -0400 Subject: polishing comments --- activesupport/lib/active_support/core_ext/array/conversions.rb | 10 +++++----- .../active_support/core_ext/class/inheritable_attributes.rb | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/core_ext/array/conversions.rb b/activesupport/lib/active_support/core_ext/array/conversions.rb index 79e3828817..7585137aca 100644 --- a/activesupport/lib/active_support/core_ext/array/conversions.rb +++ b/activesupport/lib/active_support/core_ext/array/conversions.rb @@ -58,12 +58,12 @@ class Array alias_method :to_default_s, :to_s alias_method :to_s, :to_formatted_s - # Returns a string that represents this array in XML by sending +to_xml+ - # to each element. Active Record collections delegate their representation + # Returns a string that represents the array in XML by invoking +to_xml+ + # on each element. Active Record collections delegate their representation # in XML to this method. # # All elements are expected to respond to +to_xml+, if any of them does - # not an exception is raised. + # not then an exception is raised. # # The root node reflects the class name of the first element in plural # if all elements belong to the same type and that's not Hash: @@ -115,8 +115,8 @@ class Array # # # - # By default root children have as node name the one of the root - # singularized. You can change it with the :children option. + # By default name of the node for the children of root is root.singularize. + # You can change it with the :children option. # # The +options+ hash is passed downwards: # diff --git a/activesupport/lib/active_support/core_ext/class/inheritable_attributes.rb b/activesupport/lib/active_support/core_ext/class/inheritable_attributes.rb index 7aff05dcdf..92d6dbadd4 100644 --- a/activesupport/lib/active_support/core_ext/class/inheritable_attributes.rb +++ b/activesupport/lib/active_support/core_ext/class/inheritable_attributes.rb @@ -1,14 +1,14 @@ require 'active_support/core_ext/object/duplicable' require 'active_support/core_ext/array/extract_options' -# Retain for backward compatibility. Methods are now included in Class. +# Retained for backward compatibility. Methods are now included in Class. module ClassInheritableAttributes # :nodoc: end -# Allows attributes to be shared within an inheritance hierarchy, but where each descendant gets a copy of +# Allows attributes to be shared within an inheritance hierarchy. Each descendant gets a copy of # their parents' attributes, instead of just a pointer to the same. This means that the child can add elements # to, for example, an array without those additions being shared with either their parent, siblings, or -# children, which is unlike the regular class-level attributes that are shared across the entire hierarchy. +# children. This is unlike the regular class-level attributes that are shared across the entire hierarchy. # # The copies of inheritable parent attributes are added to subclasses when they are created, via the # +inherited+ hook. -- cgit v1.2.3 From e7920a3bde47f1f788fc8d6b8cb00861a78047f8 Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Tue, 27 Jul 2010 16:30:56 -0400 Subject: clarifying description for class_attribute method --- activesupport/lib/active_support/core_ext/class/attribute.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/core_ext/class/attribute.rb b/activesupport/lib/active_support/core_ext/class/attribute.rb index 576366e496..83b2695606 100644 --- a/activesupport/lib/active_support/core_ext/class/attribute.rb +++ b/activesupport/lib/active_support/core_ext/class/attribute.rb @@ -2,8 +2,8 @@ require 'active_support/core_ext/kernel/singleton_class' require 'active_support/core_ext/module/remove_method' class Class - # Declare a class-level attribute whose value is inheritable and - # overwritable by subclasses: + # Declare a class-level attribute whose value is inheritable by subclasses. + # Subclasses can change their own value and it will not impact parent class. # # class Base # class_attribute :setting -- cgit v1.2.3 From e17e08efef68e9865cfbd5c0155b3d9734339192 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Wed, 28 Jul 2010 03:49:04 +0200 Subject: adds test coverage for edge-cases of Array.wrap, and better documentation for how it differs from Kernel#Array --- .../lib/active_support/core_ext/array/wrap.rb | 13 +++++++++---- activesupport/test/core_ext/array_ext_test.rb | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+), 4 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/core_ext/array/wrap.rb b/activesupport/lib/active_support/core_ext/array/wrap.rb index e211bdeeca..09a1c2e5a1 100644 --- a/activesupport/lib/active_support/core_ext/array/wrap.rb +++ b/activesupport/lib/active_support/core_ext/array/wrap.rb @@ -1,9 +1,14 @@ class Array - # Wraps the object in an Array unless it's an Array. Converts the - # object to an Array using #to_ary if it implements that. + # Array.wrap is like Kernel#Array except: # - # It differs with Array() in that it does not call +to_a+ on - # the argument: + # * If the argument responds to +to_ary+ the method is invoked. Kernel#Array + # moves on to try +to_a+ if the returned value is +nil+, but Arraw.wrap returns + # such a +nil+ right away. + # * If the returned value from +to_ary+ is neither +nil+ nor an +Array+ object, Kernel#Array + # raises an exception, while Array.wrap does not, it just returns the value. + # * It does not call +to_a+ on the argument, though special-cases +nil+ to return an empty array. + # + # The last point is particularly worth comparing for some enumerables: # # Array(:foo => :bar) # => [[:foo, :bar]] # Array.wrap(:foo => :bar) # => [{:foo => :bar}] diff --git a/activesupport/test/core_ext/array_ext_test.rb b/activesupport/test/core_ext/array_ext_test.rb index 54376deee5..009a254c64 100644 --- a/activesupport/test/core_ext/array_ext_test.rb +++ b/activesupport/test/core_ext/array_ext_test.rb @@ -398,6 +398,18 @@ class ArrayWrapperTests < Test::Unit::TestCase def method_missing(*a) @target.send(*a) end end + class DoubtfulToAry + def to_ary + :not_an_array + end + end + + class NilToAry + def to_ary + nil + end + end + def test_array ary = %w(foo bar) assert_same ary, Array.wrap(ary) @@ -438,4 +450,12 @@ class ArrayWrapperTests < Test::Unit::TestCase o = Struct.new(:foo).new(123) assert_equal [o], Array.wrap(o) end + + def test_wrap_returns_nil_if_to_ary_returns_nil + assert_nil Array.wrap(NilToAry.new) + end + + def test_wrap_does_not_complain_if_to_ary_does_not_return_an_array + assert_equal DoubtfulToAry.new.to_ary, Array.wrap(DoubtfulToAry.new) + end end -- cgit v1.2.3 From 194ec3d165f6ef4dd53391d6c959c57ed60507b4 Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Tue, 27 Jul 2010 21:22:47 +0800 Subject: removing unused variable --- activesupport/lib/active_support/cache.rb | 2 -- 1 file changed, 2 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/cache.rb b/activesupport/lib/active_support/cache.rb index bef9c98ecf..0efb1a9458 100644 --- a/activesupport/lib/active_support/cache.rb +++ b/activesupport/lib/active_support/cache.rb @@ -19,8 +19,6 @@ module ActiveSupport autoload :SynchronizedMemoryStore, 'active_support/cache/synchronized_memory_store' autoload :CompressedMemCacheStore, 'active_support/cache/compressed_mem_cache_store' - EMPTY_OPTIONS = {}.freeze - # These options mean something to all cache implementations. Individual cache # implementations may support additional options. UNIVERSAL_OPTIONS = [:namespace, :compress, :compress_threshold, :expires_in, :race_condition_ttl] -- cgit v1.2.3 From 3265af5c8b98da0d9f292fcc2feddc2da02e652d Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Tue, 27 Jul 2010 21:41:11 +0800 Subject: adding more test cases for expand_cache_key --- activesupport/test/caching_test.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'activesupport') diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb index 212c1f82a8..ed9b53f593 100644 --- a/activesupport/test/caching_test.rb +++ b/activesupport/test/caching_test.rb @@ -7,6 +7,16 @@ class CacheKeyTest < ActiveSupport::TestCase assert_equal '1/2/true', ActiveSupport::Cache.expand_cache_key([1, '2', true]) assert_equal 'name/1/2/true', ActiveSupport::Cache.expand_cache_key([1, '2', true], :name) end + + def test_expand_cache_key_with_rails_cache_id + ENV['RAILS_CACHE_ID'] = 'c99' + assert_equal 'c99/foo', ActiveSupport::Cache.expand_cache_key(:foo) + assert_equal 'c99/foo', ActiveSupport::Cache.expand_cache_key([:foo]) + assert_equal 'c99/c99/foo/c99/bar', ActiveSupport::Cache.expand_cache_key([:foo, :bar]) + assert_equal 'nm/c99/foo', ActiveSupport::Cache.expand_cache_key(:foo, :nm) + assert_equal 'nm/c99/foo', ActiveSupport::Cache.expand_cache_key([:foo], :nm) + assert_equal 'nm/c99/c99/foo/c99/bar', ActiveSupport::Cache.expand_cache_key([:foo, :bar], :nm) + end end class CacheStoreSettingTest < ActiveSupport::TestCase -- cgit v1.2.3 From 7d29627be91027cb6b616d21bc97e5066901d907 Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Tue, 27 Jul 2010 21:47:59 +0800 Subject: test cases for rails_app_version in AS cache.rb --- activesupport/test/caching_test.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'activesupport') diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb index ed9b53f593..8497e44554 100644 --- a/activesupport/test/caching_test.rb +++ b/activesupport/test/caching_test.rb @@ -9,6 +9,7 @@ class CacheKeyTest < ActiveSupport::TestCase end def test_expand_cache_key_with_rails_cache_id + ENV['RAILS_APP_VERSION'] = nil ENV['RAILS_CACHE_ID'] = 'c99' assert_equal 'c99/foo', ActiveSupport::Cache.expand_cache_key(:foo) assert_equal 'c99/foo', ActiveSupport::Cache.expand_cache_key([:foo]) @@ -17,6 +18,19 @@ class CacheKeyTest < ActiveSupport::TestCase assert_equal 'nm/c99/foo', ActiveSupport::Cache.expand_cache_key([:foo], :nm) assert_equal 'nm/c99/c99/foo/c99/bar', ActiveSupport::Cache.expand_cache_key([:foo, :bar], :nm) end + + def test_expand_cache_key_with_rails_app_version + ENV['RAILS_CACHE_ID'] = nil + ENV['RAILS_APP_VERSION'] = 'rails3' + assert_equal 'rails3/foo', ActiveSupport::Cache.expand_cache_key(:foo) + end + + def test_expand_cache_key_rails_cache_id_should_win_over_rails_app_version + ENV['RAILS_CACHE_ID'] = 'c99' + ENV['RAILS_APP_VERSION'] = 'rails3' + assert_equal 'c99/foo', ActiveSupport::Cache.expand_cache_key(:foo) + end + end class CacheStoreSettingTest < ActiveSupport::TestCase -- cgit v1.2.3 From 4952a80200cf916636b1e0ca11985bbd09f42a80 Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Tue, 27 Jul 2010 21:57:15 +0800 Subject: adding test for respond_to cache_key and cleaning up the ENV settings --- activesupport/test/caching_test.rb | 47 ++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 14 deletions(-) (limited to 'activesupport') diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb index 8497e44554..b79a7bbaec 100644 --- a/activesupport/test/caching_test.rb +++ b/activesupport/test/caching_test.rb @@ -9,26 +9,45 @@ class CacheKeyTest < ActiveSupport::TestCase end def test_expand_cache_key_with_rails_cache_id - ENV['RAILS_APP_VERSION'] = nil - ENV['RAILS_CACHE_ID'] = 'c99' - assert_equal 'c99/foo', ActiveSupport::Cache.expand_cache_key(:foo) - assert_equal 'c99/foo', ActiveSupport::Cache.expand_cache_key([:foo]) - assert_equal 'c99/c99/foo/c99/bar', ActiveSupport::Cache.expand_cache_key([:foo, :bar]) - assert_equal 'nm/c99/foo', ActiveSupport::Cache.expand_cache_key(:foo, :nm) - assert_equal 'nm/c99/foo', ActiveSupport::Cache.expand_cache_key([:foo], :nm) - assert_equal 'nm/c99/c99/foo/c99/bar', ActiveSupport::Cache.expand_cache_key([:foo, :bar], :nm) + begin + ENV['RAILS_CACHE_ID'] = 'c99' + assert_equal 'c99/foo', ActiveSupport::Cache.expand_cache_key(:foo) + assert_equal 'c99/foo', ActiveSupport::Cache.expand_cache_key([:foo]) + assert_equal 'c99/c99/foo/c99/bar', ActiveSupport::Cache.expand_cache_key([:foo, :bar]) + assert_equal 'nm/c99/foo', ActiveSupport::Cache.expand_cache_key(:foo, :nm) + assert_equal 'nm/c99/foo', ActiveSupport::Cache.expand_cache_key([:foo], :nm) + assert_equal 'nm/c99/c99/foo/c99/bar', ActiveSupport::Cache.expand_cache_key([:foo, :bar], :nm) + ensure + ENV['RAILS_CACHE_ID'] = nil + end end def test_expand_cache_key_with_rails_app_version - ENV['RAILS_CACHE_ID'] = nil - ENV['RAILS_APP_VERSION'] = 'rails3' - assert_equal 'rails3/foo', ActiveSupport::Cache.expand_cache_key(:foo) + begin + ENV['RAILS_APP_VERSION'] = 'rails3' + assert_equal 'rails3/foo', ActiveSupport::Cache.expand_cache_key(:foo) + ensure + ENV['RAILS_APP_VERSION'] = nil + end end def test_expand_cache_key_rails_cache_id_should_win_over_rails_app_version - ENV['RAILS_CACHE_ID'] = 'c99' - ENV['RAILS_APP_VERSION'] = 'rails3' - assert_equal 'c99/foo', ActiveSupport::Cache.expand_cache_key(:foo) + begin + ENV['RAILS_CACHE_ID'] = 'c99' + ENV['RAILS_APP_VERSION'] = 'rails3' + assert_equal 'c99/foo', ActiveSupport::Cache.expand_cache_key(:foo) + ensure + ENV['RAILS_CACHE_ID'] = nil + ENV['RAILS_APP_VERSION'] = nil + end + end + + def test_respond_to_cache_key + key = 'foo' + def key.cache_key + :foo_key + end + assert_equal 'foo_key', ActiveSupport::Cache.expand_cache_key(key) end end -- cgit v1.2.3 From f3b50b11c7cba1ae21888c755cbeabf3b3aca072 Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Wed, 28 Jul 2010 09:53:24 -0400 Subject: updating description of how class_attribute works --- activesupport/lib/active_support/core_ext/class/attribute.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/core_ext/class/attribute.rb b/activesupport/lib/active_support/core_ext/class/attribute.rb index 83b2695606..cee3f04354 100644 --- a/activesupport/lib/active_support/core_ext/class/attribute.rb +++ b/activesupport/lib/active_support/core_ext/class/attribute.rb @@ -18,6 +18,11 @@ class Class # Subclass.setting # => false # Base.setting # => true # + # In the above case as long as Subclass does not assign a value to setting + # by performing Subclass.setting = _something_ , Subclass.setting + # would read value assigned to parent class. Once Subclass assigns a value then + # the value assigned by Subclass would be returned. + # # This matches normal Ruby method inheritance: think of writing an attribute # on a subclass as overriding the reader method. # -- cgit v1.2.3 From ff7e17d33e8042fa430fd637ef3433ef7367dc30 Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Wed, 28 Jul 2010 10:05:10 -0400 Subject: adding some comments to cattr_accessor method --- .../lib/active_support/core_ext/class/attribute_accessors.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb b/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb index feef5d2d57..cdc7cfc1d4 100644 --- a/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb +++ b/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb @@ -3,11 +3,17 @@ require 'active_support/core_ext/array/extract_options' # Extends the class object with class and instance accessors for class attributes, # just like the native attr* accessors for instance attributes. # +# Note that unlike +class_attribute+, if a subclass changes the value then that would +# also change the value for parent class. Similarly if parent class changes the value +# then that would change the value of subclasses too. +# # class Person # cattr_accessor :hair_colors # end # # Person.hair_colors = [:brown, :black, :blonde, :red] +# Person.hair_colors #=> [:brown, :black, :blonde, :red] +# Person.new.hair_colors #=> [:brown, :black, :blonde, :red] class Class def cattr_reader(*syms) options = syms.extract_options! -- cgit v1.2.3 From eb902d6c00f64e7060f24fa3b243d5b6dea98cac Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Wed, 28 Jul 2010 10:08:00 -0400 Subject: clarifying the instance_write option with an example --- activesupport/lib/active_support/core_ext/class/attribute.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/core_ext/class/attribute.rb b/activesupport/lib/active_support/core_ext/class/attribute.rb index cee3f04354..af8202ae2c 100644 --- a/activesupport/lib/active_support/core_ext/class/attribute.rb +++ b/activesupport/lib/active_support/core_ext/class/attribute.rb @@ -41,7 +41,11 @@ class Class # # To opt out of the instance writer method, pass :instance_writer => false. # - # object.setting = false # => NoMethodError + # class Base + # class_attribute :setting, :instance_write => false + # end + # + # Base.new.setting = false # => NoMethodError def class_attribute(*attrs) instance_writer = !attrs.last.is_a?(Hash) || attrs.pop[:instance_writer] -- cgit v1.2.3 From 5b10e47593ed21fedba2401e3ad1f360e2cf0706 Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Wed, 28 Jul 2010 10:13:11 -0400 Subject: adding comment specifying that cattr_accessor also supports instance_write and instance_rader option --- .../lib/active_support/core_ext/class/attribute_accessors.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb b/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb index cdc7cfc1d4..4e35b1b488 100644 --- a/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb +++ b/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb @@ -14,6 +14,16 @@ require 'active_support/core_ext/array/extract_options' # Person.hair_colors = [:brown, :black, :blonde, :red] # Person.hair_colors #=> [:brown, :black, :blonde, :red] # Person.new.hair_colors #=> [:brown, :black, :blonde, :red] +# +# To opt out of the instance writer method, pass :instance_writer => false. +# To opt out of the instance reader method, pass :instance_reader => false. +# +# class Person +# cattr_accessor :hair_colors, :instance_writer => false, :instance_reader => false +# end +# +# Person.new.hair_colors = [:brown] # => NoMethodError +# Person.new.hair_colors # => NoMethodError class Class def cattr_reader(*syms) options = syms.extract_options! -- cgit v1.2.3 From 2d601e4ea30ab1e2de97c53c550b60e1c98b144a Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Wed, 28 Jul 2010 10:56:10 -0400 Subject: editing a sentence --- activesupport/lib/active_support/cache.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/cache.rb b/activesupport/lib/active_support/cache.rb index 1445cec446..acf2d2bc85 100644 --- a/activesupport/lib/active_support/cache.rb +++ b/activesupport/lib/active_support/cache.rb @@ -131,7 +131,7 @@ module ActiveSupport # # All caches support auto expiring content after a specified number of seconds. # To set the cache entry time to live, you can either specify +:expires_in+ as - # an option to the constructor to have it affect all entries or to the +fetch+ + # an option to the constructor to affect all entries or to the +fetch+ # or +write+ methods for just one entry. # # cache = ActiveSupport::Cache::MemoryStore.new(:expire_in => 5.minutes) -- cgit v1.2.3 From dea8bf5dc42ea081cce1702e3a7566cbdef50a69 Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Wed, 28 Jul 2010 11:22:35 -0400 Subject: editing the documentation regarding :race_condition_ttl and :expires_in option in AS cache --- activesupport/lib/active_support/cache.rb | 45 ++++++++++++++++--------------- 1 file changed, 23 insertions(+), 22 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/cache.rb b/activesupport/lib/active_support/cache.rb index acf2d2bc85..037cfffae2 100644 --- a/activesupport/lib/active_support/cache.rb +++ b/activesupport/lib/active_support/cache.rb @@ -129,13 +129,6 @@ module ActiveSupport # cache.namespace = lambda { @last_mod_time } # Set the namespace to a variable # @last_mod_time = Time.now # Invalidate the entire cache by changing namespace # - # All caches support auto expiring content after a specified number of seconds. - # To set the cache entry time to live, you can either specify +:expires_in+ as - # an option to the constructor to affect all entries or to the +fetch+ - # or +write+ methods for just one entry. - # - # cache = ActiveSupport::Cache::MemoryStore.new(:expire_in => 5.minutes) - # cache.write(key, value, :expire_in => 1.minute) # Set a lower value for one entry # # Caches can also store values in a compressed format to save space and reduce # time spent sending data. Since there is some overhead, values must be large @@ -211,23 +204,30 @@ module ActiveSupport # Setting :compress will store a large cache entry set by the call # in a compressed format. # - # Setting :expires_in will set an expiration time on the cache - # entry if it is set by call. # - # Setting :race_condition_ttl will invoke logic on entries set with - # an :expires_in option. If an entry is found in the cache that is - # expired and it has been expired for less than the number of seconds specified - # by this option and a block was passed to the method call, then the expiration - # future time of the entry in the cache will be updated to that many seconds - # in the and the block will be evaluated and written to the cache. + # Setting :expires_in will set an expiration time on the cache. All caches + # support auto expiring content after a specified number of seconds. This value can + # be specified as an option to the construction in which call all entries will be + # affected. Or it can be supplied to the +fetch+ or +write+ method for just one entry. + # + # cache = ActiveSupport::Cache::MemoryStore.new(:expire_in => 5.minutes) + # cache.write(key, value, :expire_in => 1.minute) # Set a lower value for one entry + # + # Setting :race_condition_ttl is very useful in situations where a cache entry + # is used very frequently unver heavy load. If a cache expires and due to heavy load + # seven different processes will try to read data natively and then they all will try to + # write to cache. To avoid that case the first process to find an expired cache entry will + # bump the cache expiration time by the value set in :race_condition_ttl. Yes + # this process is extending the time for a stale value by another few seconds. Because + # of extended life of the previous cache, other processes will continue to use slightly + # stale data for a just a big longer. In the meantime that first process will go ahead + # and will write into cache the new value. After that all the processes will start + # getting new value. The key is to keep :race_condition_ttl small. # - # This is very useful in situations where a cache entry is used very frequently - # under heavy load. The first process to find an expired cache entry will then - # become responsible for regenerating that entry while other processes continue - # to use the slightly out of date entry. This can prevent race conditions where - # too many processes are trying to regenerate the entry all at once. If the - # process regenerating the entry errors out, the entry will be regenerated - # after the specified number of seconds. + # If the process regenerating the entry errors out, the entry will be regenerated + # after the specified number of seconds. Also note that the life of stale cache is + # extended only if it expired recently. Otherwise a new value is generated and + # :race_condition_ttl does not play any role. # # # Set all values to expire after one minute. # cache = ActiveSupport::Cache::MemoryCache.new(:expires_in => 1.minute) @@ -252,6 +252,7 @@ module ActiveSupport # # # val_1 => "new value 1" # # val_2 => "original value" + # # sleep 10 # First thread extend the life of cache by another 10 seconds # # cache.fetch("foo") => "new value 1" # # Other options will be handled by the specific cache store implementation. -- cgit v1.2.3 From 7c3d479c4b8ae5667ead1163d4ce713c5ae73629 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 28 Jul 2010 08:49:54 -0700 Subject: More documentation to class_attribute. --- .../lib/active_support/core_ext/class/attribute.rb | 35 +++++++++++++++------- 1 file changed, 24 insertions(+), 11 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/core_ext/class/attribute.rb b/activesupport/lib/active_support/core_ext/class/attribute.rb index af8202ae2c..bfa57fe1f7 100644 --- a/activesupport/lib/active_support/core_ext/class/attribute.rb +++ b/activesupport/lib/active_support/core_ext/class/attribute.rb @@ -18,17 +18,34 @@ class Class # Subclass.setting # => false # Base.setting # => true # - # In the above case as long as Subclass does not assign a value to setting - # by performing Subclass.setting = _something_ , Subclass.setting - # would read value assigned to parent class. Once Subclass assigns a value then - # the value assigned by Subclass would be returned. + # In the above case as long as Subclass does not assign a value to setting + # by performing Subclass.setting = _something_ , Subclass.setting + # would read value assigned to parent class. Once Subclass assigns a value then + # the value assigned by Subclass would be returned. # # This matches normal Ruby method inheritance: think of writing an attribute - # on a subclass as overriding the reader method. + # on a subclass as overriding the reader method. However, you need to be aware + # when using +class_attribute+ with mutable structures as +Array+ or +Hash+. + # In such cases, you don't want to do changes in places but use setters: + # + # Base.setting = [] + # Base.setting #=> [] + # Subclass.setting #=> [] + # + # # Appending in child changes both parent and child because it is the same object: + # Subclass.setting << :foo + # Base.setting #=> [:foo] + # Subclass.setting #=> [:foo] + # + # # Use setters to not propagate changes: + # Base.setting = [] + # Subclass.setting += [:foo] + # Base.setting #=> [] + # Subclass.setting #=> [:foo] # # For convenience, a query method is defined as well: # - # Subclass.setting? # => false + # Subclass.setting? # => false # # Instances may overwrite the class value in the same way: # @@ -41,11 +58,7 @@ class Class # # To opt out of the instance writer method, pass :instance_writer => false. # - # class Base - # class_attribute :setting, :instance_write => false - # end - # - # Base.new.setting = false # => NoMethodError + # object.setting = false # => NoMethodError def class_attribute(*attrs) instance_writer = !attrs.last.is_a?(Hash) || attrs.pop[:instance_writer] -- cgit v1.2.3 From 627d870c92e59fb5c2205df0ef897a525c9e85bc Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Wed, 28 Jul 2010 22:44:32 -0400 Subject: itsy bitsy changes to documentation --- .../active_support/core_ext/date/calculations.rb | 26 +++++++++++----------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/core_ext/date/calculations.rb b/activesupport/lib/active_support/core_ext/date/calculations.rb index e6a213625c..c5b54318ce 100644 --- a/activesupport/lib/active_support/core_ext/date/calculations.rb +++ b/activesupport/lib/active_support/core_ext/date/calculations.rb @@ -40,23 +40,23 @@ class Date end end - # Tells whether the Date object's date lies in the past + # Returns true if the Date object's date lies in the past. Otherwise returns false. def past? self < ::Date.current end - # Tells whether the Date object's date is today + # Returns true if the Date object's date is today. def today? self.to_date == ::Date.current # we need the to_date because of DateTime end - # Tells whether the Date object's date lies in the future + # Returns true if the Date object's date lies in the future. def future? self > ::Date.current end # Converts Date to a Time (or DateTime if necessary) with the time portion set to the beginning of the day (0:00) - # and then subtracts the specified number of seconds + # and then subtracts the specified number of seconds. def ago(seconds) to_time_in_current_zone.since(-seconds) end @@ -127,22 +127,22 @@ class Date ) end - # Returns a new Date/DateTime representing the time a number of specified months ago + # Returns a new Date/DateTime representing the time a number of specified months ago. def months_ago(months) advance(:months => -months) end - # Returns a new Date/DateTime representing the time a number of specified months in the future + # Returns a new Date/DateTime representing the time a number of specified months in the future. def months_since(months) advance(:months => months) end - # Returns a new Date/DateTime representing the time a number of specified years ago + # Returns a new Date/DateTime representing the time a number of specified years ago. def years_ago(years) advance(:years => -years) end - # Returns a new Date/DateTime representing the time a number of specified years in the future + # Returns a new Date/DateTime representing the time a number of specified years in the future. def years_since(years) advance(:years => years) end @@ -152,22 +152,22 @@ class Date years_ago(1) end unless method_defined?(:prev_year) - # Short-hand for years_since(1) + # Shorthand for years_since(1) def next_year years_since(1) end unless method_defined?(:next_year) - # Short-hand for months_ago(1) + # Shorthand for months_ago(1) def prev_month months_ago(1) end unless method_defined?(:prev_month) - # Short-hand for months_since(1) + # Shorthand for months_since(1) def next_month months_since(1) end unless method_defined?(:next_month) - # Returns a new Date/DateTime representing the "start" of this week (i.e, Monday; DateTime objects will have time set to 0:00) + # Returns a new Date/DateTime representing the "start" of this week (i.e, Monday; DateTime objects will have time set to 0:00). def beginning_of_week days_to_monday = self.wday!=0 ? self.wday-1 : 6 result = self - days_to_monday @@ -176,7 +176,7 @@ class Date alias :monday :beginning_of_week alias :at_beginning_of_week :beginning_of_week - # Returns a new Date/DateTime representing the end of this week (Sunday, DateTime objects will have time set to 23:59:59) + # Returns a new Date/DateTime representing the end of this week (Sunday, DateTime objects will have time set to 23:59:59). def end_of_week days_to_sunday = self.wday!=0 ? 7-self.wday : 0 result = self + days_to_sunday.days -- cgit v1.2.3 From d04c6f2ff6047fe03dae0ca162948befa246c7e4 Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Thu, 29 Jul 2010 08:51:06 -0700 Subject: Add a missing require in 'active_support/core_ext/string/inflections' --- activesupport/lib/active_support/core_ext/string/inflections.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/core_ext/string/inflections.rb b/activesupport/lib/active_support/core_ext/string/inflections.rb index 66c4034781..f33e4959f9 100644 --- a/activesupport/lib/active_support/core_ext/string/inflections.rb +++ b/activesupport/lib/active_support/core_ext/string/inflections.rb @@ -1,3 +1,4 @@ +require 'active_support/inflector/methods' # String inflections define new methods on the String class to transform names for different purposes. # For instance, you can figure out the name of a database from the name of a class. # -- cgit v1.2.3 From 3c3ff1377d17b584dd14d85c7cecab59ddff2679 Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Thu, 29 Jul 2010 13:05:54 -0400 Subject: Adding documentation regarding lazy_load_hooks --- activesupport/lib/active_support/lazy_load_hooks.rb | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/lazy_load_hooks.rb b/activesupport/lib/active_support/lazy_load_hooks.rb index 3664431a28..ef43fc0431 100644 --- a/activesupport/lib/active_support/lazy_load_hooks.rb +++ b/activesupport/lib/active_support/lazy_load_hooks.rb @@ -1,3 +1,22 @@ +# lazy_load_hooks allows rails to lazily load a lot of components and thus making the app boot faster. Because of +# this feature now there is no need to require ActiveRecord::Base at boot time purely to apply configuration. Instead +# a hook is registered that applies configuration once ActiveRecord::Base is loaded. Here ActiveRecord::Base is used +# as example but this feature can be applied elsewhere too. +# +# Here is an example where +on_load+ method is called to register a hook. +# +# initializer "active_record.initialize_timezone" do +# ActiveSupport.on_load(:active_record) do +# self.time_zone_aware_attributes = true +# self.default_timezone = :utc +# end +# end +# +# When the entirety of +activerecord/lib/active_record/base.rb+ has been evaluated then +run_load_hooks+ is invoked. +# The very last line of +activerecord/lib/active_record/base.rb+ is: +# +# ActiveSupport.run_load_hooks(:active_record, ActiveRecord::Base) +# module ActiveSupport @load_hooks = Hash.new {|h,k| h[k] = [] } @loaded = {} @@ -24,4 +43,4 @@ module ActiveSupport execute_hook(base, options, hook) end end -end \ No newline at end of file +end -- cgit v1.2.3 From 755af497555fde16db86f7e51f6462b0aca79b49 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Fri, 30 Jul 2010 02:30:04 +0200 Subject: edit pass to apply API guideline wrt the use of "# =>" in example code --- .../lib/active_support/core_ext/array/uniq_by.rb | 2 +- .../lib/active_support/core_ext/enumerable.rb | 3 +- .../active_support/core_ext/string/multibyte.rb | 10 +-- .../lib/active_support/multibyte/chars.rb | 73 +++++++++++----------- .../lib/active_support/multibyte/unicode.rb | 8 +-- activesupport/lib/active_support/notifications.rb | 6 +- activesupport/lib/active_support/secure_random.rb | 26 ++++---- 7 files changed, 65 insertions(+), 63 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/core_ext/array/uniq_by.rb b/activesupport/lib/active_support/core_ext/array/uniq_by.rb index a09b2302fd..bd5c7a187f 100644 --- a/activesupport/lib/active_support/core_ext/array/uniq_by.rb +++ b/activesupport/lib/active_support/core_ext/array/uniq_by.rb @@ -2,7 +2,7 @@ class Array # Return an unique array based on the criteria given as a proc. # # [1, 2, 3, 4].uniq_by { |i| i.odd? } - # #=> [1, 2] + # # => [1, 2] # def uniq_by hash, array = {}, [] diff --git a/activesupport/lib/active_support/core_ext/enumerable.rb b/activesupport/lib/active_support/core_ext/enumerable.rb index d0821a7c68..f76ed401cd 100644 --- a/activesupport/lib/active_support/core_ext/enumerable.rb +++ b/activesupport/lib/active_support/core_ext/enumerable.rb @@ -66,7 +66,8 @@ module Enumerable # +memo+ to the block. Handy for building up hashes or # reducing collections down to one object. Examples: # - # %w(foo bar).each_with_object({}) { |str, hsh| hsh[str] = str.upcase } #=> {'foo' => 'FOO', 'bar' => 'BAR'} + # %w(foo bar).each_with_object({}) { |str, hsh| hsh[str] = str.upcase } + # # => {'foo' => 'FOO', 'bar' => 'BAR'} # # *Note* that you can't use immutable objects like numbers, true or false as # the memo. You would think the following returns 120, but since the memo is diff --git a/activesupport/lib/active_support/core_ext/string/multibyte.rb b/activesupport/lib/active_support/core_ext/string/multibyte.rb index 16ccd36458..0b974f5e0a 100644 --- a/activesupport/lib/active_support/core_ext/string/multibyte.rb +++ b/activesupport/lib/active_support/core_ext/string/multibyte.rb @@ -12,11 +12,11 @@ class String # class. If the proxy class doesn't respond to a certain method, it's forwarded to the encapsuled string. # # name = 'Claus Müller' - # name.reverse #=> "rell??M sualC" - # name.length #=> 13 + # name.reverse # => "rell??M sualC" + # name.length # => 13 # - # name.mb_chars.reverse.to_s #=> "rellüM sualC" - # name.mb_chars.length #=> 12 + # name.mb_chars.reverse.to_s # => "rellüM sualC" + # name.mb_chars.length # => 12 # # In Ruby 1.9 and newer +mb_chars+ returns +self+ because String is (mostly) encoding aware. This means that # it becomes easy to run one version of your code on multiple Ruby versions. @@ -26,7 +26,7 @@ class String # All the methods on the Chars proxy which normally return a string will return a Chars object. This allows # method chaining on the result of any of these methods. # - # name.mb_chars.reverse.length #=> 12 + # name.mb_chars.reverse.length # => 12 # # == Interoperability and configuration # diff --git a/activesupport/lib/active_support/multibyte/chars.rb b/activesupport/lib/active_support/multibyte/chars.rb index 51c2a0edac..019fb2df06 100644 --- a/activesupport/lib/active_support/multibyte/chars.rb +++ b/activesupport/lib/active_support/multibyte/chars.rb @@ -11,7 +11,7 @@ module ActiveSupport #:nodoc: # String methods are proxied through the Chars object, and can be accessed through the +mb_chars+ method. Methods # which would normally return a String object now return a Chars object so methods can be chained. # - # "The Perfect String ".mb_chars.downcase.strip.normalize #=> "the perfect string" + # "The Perfect String ".mb_chars.downcase.strip.normalize # => "the perfect string" # # Chars objects are perfectly interchangeable with String objects as long as no explicit class checks are made. # If certain methods do explicitly check the class, call +to_s+ before you pass chars objects to them. @@ -83,12 +83,13 @@ module ActiveSupport #:nodoc: include Comparable - # Returns -1, 0 or +1 depending on whether the Chars object is to be sorted before, - # equal or after the object on the right side of the operation. It accepts any object that implements +to_s+. - # See String#<=> for more details. + # Returns -1, 0, or 1, depending on whether the Chars object is to be sorted before, + # equal or after the object on the right side of the operation. It accepts any object + # that implements +to_s+: # - # Example: - # 'é'.mb_chars <=> 'ü'.mb_chars #=> -1 + # 'é'.mb_chars <=> 'ü'.mb_chars # => -1 + # + # See String#<=> for more details. def <=>(other) @wrapped_string <=> other.to_s end @@ -103,7 +104,7 @@ module ActiveSupport #:nodoc: # Returns a new Chars object containing the _other_ object concatenated to the string. # # Example: - # ('Café'.mb_chars + ' périferôl').to_s #=> "Café périferôl" + # ('Café'.mb_chars + ' périferôl').to_s # => "Café périferôl" def +(other) chars(@wrapped_string + other) end @@ -111,7 +112,7 @@ module ActiveSupport #:nodoc: # Like String#=~ only it returns the character offset (in codepoints) instead of the byte offset. # # Example: - # 'Café périferôl'.mb_chars =~ /ô/ #=> 12 + # 'Café périferôl'.mb_chars =~ /ô/ # => 12 def =~(other) translate_offset(@wrapped_string =~ other) end @@ -119,7 +120,7 @@ module ActiveSupport #:nodoc: # Inserts the passed string at specified codepoint offsets. # # Example: - # 'Café'.mb_chars.insert(4, ' périferôl').to_s #=> "Café périferôl" + # 'Café'.mb_chars.insert(4, ' périferôl').to_s # => "Café périferôl" def insert(offset, fragment) unpacked = Unicode.u_unpack(@wrapped_string) unless offset > unpacked.length @@ -135,7 +136,7 @@ module ActiveSupport #:nodoc: # Returns +true+ if contained string contains _other_. Returns +false+ otherwise. # # Example: - # 'Café'.mb_chars.include?('é') #=> true + # 'Café'.mb_chars.include?('é') # => true def include?(other) # We have to redefine this method because Enumerable defines it. @wrapped_string.include?(other) @@ -144,8 +145,8 @@ module ActiveSupport #:nodoc: # Returns the position _needle_ in the string, counting in codepoints. Returns +nil+ if _needle_ isn't found. # # Example: - # 'Café périferôl'.mb_chars.index('ô') #=> 12 - # 'Café périferôl'.mb_chars.index(/\w/u) #=> 0 + # 'Café périferôl'.mb_chars.index('ô') # => 12 + # 'Café périferôl'.mb_chars.index(/\w/u) # => 0 def index(needle, offset=0) wrapped_offset = first(offset).wrapped_string.length index = @wrapped_string.index(needle, wrapped_offset) @@ -157,8 +158,8 @@ module ActiveSupport #:nodoc: # string. Returns +nil+ if _needle_ isn't found. # # Example: - # 'Café périferôl'.mb_chars.rindex('é') #=> 6 - # 'Café périferôl'.mb_chars.rindex(/\w/u) #=> 13 + # 'Café périferôl'.mb_chars.rindex('é') # => 6 + # 'Café périferôl'.mb_chars.rindex(/\w/u) # => 13 def rindex(needle, offset=nil) offset ||= length wrapped_offset = first(offset).wrapped_string.length @@ -190,7 +191,7 @@ module ActiveSupport #:nodoc: # Returns the codepoint of the first character in the string. # # Example: - # 'こんにちは'.mb_chars.ord #=> 12371 + # 'こんにちは'.mb_chars.ord # => 12371 def ord Unicode.u_unpack(@wrapped_string)[0] end @@ -200,10 +201,10 @@ module ActiveSupport #:nodoc: # Example: # # "¾ cup".mb_chars.rjust(8).to_s - # #=> " ¾ cup" + # # => " ¾ cup" # # "¾ cup".mb_chars.rjust(8, " ").to_s # Use non-breaking whitespace - # #=> "   ¾ cup" + # # => "   ¾ cup" def rjust(integer, padstr=' ') justify(integer, :right, padstr) end @@ -213,10 +214,10 @@ module ActiveSupport #:nodoc: # Example: # # "¾ cup".mb_chars.rjust(8).to_s - # #=> "¾ cup " + # # => "¾ cup " # # "¾ cup".mb_chars.rjust(8, " ").to_s # Use non-breaking whitespace - # #=> "¾ cup   " + # # => "¾ cup   " def ljust(integer, padstr=' ') justify(integer, :left, padstr) end @@ -226,10 +227,10 @@ module ActiveSupport #:nodoc: # Example: # # "¾ cup".mb_chars.center(8).to_s - # #=> " ¾ cup " + # # => " ¾ cup " # # "¾ cup".mb_chars.center(8, " ").to_s # Use non-breaking whitespace - # #=> " ¾ cup  " + # # => " ¾ cup  " def center(integer, padstr=' ') justify(integer, :center, padstr) end @@ -244,7 +245,7 @@ module ActiveSupport #:nodoc: # instances instead of String. This makes chaining methods easier. # # Example: - # 'Café périferôl'.mb_chars.split(/é/).map { |part| part.upcase.to_s } #=> ["CAF", " P", "RIFERÔL"] + # 'Café périferôl'.mb_chars.split(/é/).map { |part| part.upcase.to_s } # => ["CAF", " P", "RIFERÔL"] def split(*args) @wrapped_string.split(*args).map { |i| i.mb_chars } end @@ -256,12 +257,12 @@ module ActiveSupport #:nodoc: # s = "Müller" # s.mb_chars[2] = "e" # Replace character with offset 2 # s - # #=> "Müeler" + # # => "Müeler" # # s = "Müller" # s.mb_chars[1, 2] = "ö" # Replace 2 characters at character offset 1 # s - # #=> "Möler" + # # => "Möler" def []=(*args) replace_by = args.pop # Indexed replace with regular expressions already works @@ -292,7 +293,7 @@ module ActiveSupport #:nodoc: # Reverses all characters in the string. # # Example: - # 'Café'.mb_chars.reverse.to_s #=> 'éfaC' + # 'Café'.mb_chars.reverse.to_s # => 'éfaC' def reverse chars(Unicode.g_unpack(@wrapped_string).reverse.flatten.pack('U*')) end @@ -301,7 +302,7 @@ module ActiveSupport #:nodoc: # character. # # Example: - # 'こんにちは'.mb_chars.slice(2..3).to_s #=> "にち" + # 'こんにちは'.mb_chars.slice(2..3).to_s # => "にち" def slice(*args) if args.size > 2 raise ArgumentError, "wrong number of arguments (#{args.size} for 1)" # Do as if we were native @@ -330,7 +331,7 @@ module ActiveSupport #:nodoc: # # Example: # s = 'こんにちは' - # s.mb_chars.limit(7) #=> "こに" + # s.mb_chars.limit(7) # => "こに" def limit(limit) slice(0...translate_offset(limit)) end @@ -338,7 +339,7 @@ module ActiveSupport #:nodoc: # Convert characters in the string to uppercase. # # Example: - # 'Laurent, où sont les tests ?'.mb_chars.upcase.to_s #=> "LAURENT, OÙ SONT LES TESTS ?" + # 'Laurent, où sont les tests ?'.mb_chars.upcase.to_s # => "LAURENT, OÙ SONT LES TESTS ?" def upcase chars(Unicode.apply_mapping @wrapped_string, :uppercase_mapping) end @@ -346,7 +347,7 @@ module ActiveSupport #:nodoc: # Convert characters in the string to lowercase. # # Example: - # 'VĚDA A VÝZKUM'.mb_chars.downcase.to_s #=> "věda a výzkum" + # 'VĚDA A VÝZKUM'.mb_chars.downcase.to_s # => "věda a výzkum" def downcase chars(Unicode.apply_mapping @wrapped_string, :lowercase_mapping) end @@ -354,7 +355,7 @@ module ActiveSupport #:nodoc: # Converts the first character to uppercase and the remainder to lowercase. # # Example: - # 'über'.mb_chars.capitalize.to_s #=> "Über" + # 'über'.mb_chars.capitalize.to_s # => "Über" def capitalize (slice(0) || chars('')).upcase + (slice(1..-1) || chars('')).downcase end @@ -382,8 +383,8 @@ module ActiveSupport #:nodoc: # Performs canonical decomposition on all the characters. # # Example: - # 'é'.length #=> 2 - # 'é'.mb_chars.decompose.to_s.length #=> 3 + # 'é'.length # => 2 + # 'é'.mb_chars.decompose.to_s.length # => 3 def decompose chars(Unicode.decompose_codepoints(:canonical, Unicode.u_unpack(@wrapped_string)).pack('U*')) end @@ -391,8 +392,8 @@ module ActiveSupport #:nodoc: # Performs composition on all the characters. # # Example: - # 'é'.length #=> 3 - # 'é'.mb_chars.compose.to_s.length #=> 2 + # 'é'.length # => 3 + # 'é'.mb_chars.compose.to_s.length # => 2 def compose chars(Unicode.compose_codepoints(Unicode.u_unpack(@wrapped_string)).pack('U*')) end @@ -400,8 +401,8 @@ module ActiveSupport #:nodoc: # Returns the number of grapheme clusters in the string. # # Example: - # 'क्षि'.mb_chars.length #=> 4 - # 'क्षि'.mb_chars.g_length #=> 3 + # 'क्षि'.mb_chars.length # => 4 + # 'क्षि'.mb_chars.g_length # => 3 def g_length Unicode.g_unpack(@wrapped_string).length end diff --git a/activesupport/lib/active_support/multibyte/unicode.rb b/activesupport/lib/active_support/multibyte/unicode.rb index 3d80f5fa58..1139783b65 100644 --- a/activesupport/lib/active_support/multibyte/unicode.rb +++ b/activesupport/lib/active_support/multibyte/unicode.rb @@ -64,7 +64,7 @@ module ActiveSupport # valid UTF-8. # # Example: - # Unicode.u_unpack('Café') #=> [67, 97, 102, 233] + # Unicode.u_unpack('Café') # => [67, 97, 102, 233] def u_unpack(string) begin string.unpack 'U*' @@ -85,8 +85,8 @@ module ActiveSupport # Unpack the string at grapheme boundaries. Returns a list of character lists. # # Example: - # Unicode.g_unpack('क्षि') #=> [[2325, 2381], [2359], [2367]] - # Unicode.g_unpack('Café') #=> [[67], [97], [102], [233]] + # Unicode.g_unpack('क्षि') # => [[2325, 2381], [2359], [2367]] + # Unicode.g_unpack('Café') # => [[67], [97], [102], [233]] def g_unpack(string) codepoints = u_unpack(string) unpacked = [] @@ -120,7 +120,7 @@ module ActiveSupport # Reverse operation of g_unpack. # # Example: - # Unicode.g_pack(Unicode.g_unpack('क्षि')) #=> 'क्षि' + # Unicode.g_pack(Unicode.g_unpack('क्षि')) # => 'क्षि' def g_pack(unpacked) (unpacked.flatten).pack('U*') end diff --git a/activesupport/lib/active_support/notifications.rb b/activesupport/lib/active_support/notifications.rb index ca9f5ae1ac..fd79188ba4 100644 --- a/activesupport/lib/active_support/notifications.rb +++ b/activesupport/lib/active_support/notifications.rb @@ -22,9 +22,9 @@ module ActiveSupport # end # # event = @events.first - # event.name #=> :render - # event.duration #=> 10 (in milliseconds) - # event.payload #=> { :extra => :information } + # event.name # => :render + # event.duration # => 10 (in milliseconds) + # event.payload # => { :extra => :information } # # When subscribing to Notifications, you can pass a pattern, to only consume # events that match the pattern: diff --git a/activesupport/lib/active_support/secure_random.rb b/activesupport/lib/active_support/secure_random.rb index cfbce4d754..73344498cb 100644 --- a/activesupport/lib/active_support/secure_random.rb +++ b/activesupport/lib/active_support/secure_random.rb @@ -26,25 +26,25 @@ module ActiveSupport # == Example # # # random hexadecimal string. - # p SecureRandom.hex(10) #=> "52750b30ffbc7de3b362" - # p SecureRandom.hex(10) #=> "92b15d6c8dc4beb5f559" - # p SecureRandom.hex(11) #=> "6aca1b5c58e4863e6b81b8" - # p SecureRandom.hex(12) #=> "94b2fff3e7fd9b9c391a2306" - # p SecureRandom.hex(13) #=> "39b290146bea6ce975c37cfc23" + # p SecureRandom.hex(10) # => "52750b30ffbc7de3b362" + # p SecureRandom.hex(10) # => "92b15d6c8dc4beb5f559" + # p SecureRandom.hex(11) # => "6aca1b5c58e4863e6b81b8" + # p SecureRandom.hex(12) # => "94b2fff3e7fd9b9c391a2306" + # p SecureRandom.hex(13) # => "39b290146bea6ce975c37cfc23" # ... # # # random base64 string. - # p SecureRandom.base64(10) #=> "EcmTPZwWRAozdA==" - # p SecureRandom.base64(10) #=> "9b0nsevdwNuM/w==" - # p SecureRandom.base64(10) #=> "KO1nIU+p9DKxGg==" - # p SecureRandom.base64(11) #=> "l7XEiFja+8EKEtY=" - # p SecureRandom.base64(12) #=> "7kJSM/MzBJI+75j8" - # p SecureRandom.base64(13) #=> "vKLJ0tXBHqQOuIcSIg==" + # p SecureRandom.base64(10) # => "EcmTPZwWRAozdA==" + # p SecureRandom.base64(10) # => "9b0nsevdwNuM/w==" + # p SecureRandom.base64(10) # => "KO1nIU+p9DKxGg==" + # p SecureRandom.base64(11) # => "l7XEiFja+8EKEtY=" + # p SecureRandom.base64(12) # => "7kJSM/MzBJI+75j8" + # p SecureRandom.base64(13) # => "vKLJ0tXBHqQOuIcSIg==" # ... # # # random binary string. - # p SecureRandom.random_bytes(10) #=> "\016\t{\370g\310pbr\301" - # p SecureRandom.random_bytes(10) #=> "\323U\030TO\234\357\020\a\337" + # p SecureRandom.random_bytes(10) # => "\016\t{\370g\310pbr\301" + # p SecureRandom.random_bytes(10) # => "\323U\030TO\234\357\020\a\337" # ... module SecureRandom # SecureRandom.random_bytes generates a random binary string. -- cgit v1.2.3 From d277b823d0d455c2d7a18cc0eb334890a32ad30e Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Thu, 29 Jul 2010 22:53:21 -0700 Subject: Add another missing require in 'active_support/inflector/inflections' --- activesupport/lib/active_support/core_ext/string/inflections.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/core_ext/string/inflections.rb b/activesupport/lib/active_support/core_ext/string/inflections.rb index f33e4959f9..32913a06ad 100644 --- a/activesupport/lib/active_support/core_ext/string/inflections.rb +++ b/activesupport/lib/active_support/core_ext/string/inflections.rb @@ -1,4 +1,5 @@ require 'active_support/inflector/methods' +require 'active_support/inflector/inflections' # String inflections define new methods on the String class to transform names for different purposes. # For instance, you can figure out the name of a database from the name of a class. # -- cgit v1.2.3 From 95e9ced5815782980230221d6a0b33fde2d74c98 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Fri, 30 Jul 2010 11:27:25 -0300 Subject: Make options an attr_reader --- activesupport/lib/active_support/cache.rb | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/cache.rb b/activesupport/lib/active_support/cache.rb index 8e90de110a..30195bdea5 100644 --- a/activesupport/lib/active_support/cache.rb +++ b/activesupport/lib/active_support/cache.rb @@ -138,7 +138,7 @@ module ActiveSupport cattr_accessor :logger, :instance_writer => true - attr_reader :silence + attr_reader :silence, :options alias :silence? :silence # Create a new cache. The options will be passed to any write method calls except @@ -147,11 +147,6 @@ module ActiveSupport @options = options ? options.dup : {} end - # Get the default options set when the cache was created. - def options - @options ||= {} - end - # Silence the logger. def silence! @silence = true -- cgit v1.2.3 From 5132081975810afade4d783e68731b06d7f37665 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Fri, 30 Jul 2010 16:05:51 -0300 Subject: AS gem doesn't depend on nokogiri so shows a nicer error if users haven't installed --- activesupport/lib/active_support/xml_mini/nokogiri.rb | 7 ++++++- activesupport/lib/active_support/xml_mini/nokogirisax.rb | 9 +++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/xml_mini/nokogiri.rb b/activesupport/lib/active_support/xml_mini/nokogiri.rb index eb61a7fc22..e03a744257 100644 --- a/activesupport/lib/active_support/xml_mini/nokogiri.rb +++ b/activesupport/lib/active_support/xml_mini/nokogiri.rb @@ -1,4 +1,9 @@ -require 'nokogiri' +begin + require 'nokogiri' +rescue LoadError => e + $stderr.puts "You don't have nokogiri installed in your application. Please add it to your Gemfile and run bundle install" + raise e +end require 'active_support/core_ext/object/blank' # = XmlMini Nokogiri implementation diff --git a/activesupport/lib/active_support/xml_mini/nokogirisax.rb b/activesupport/lib/active_support/xml_mini/nokogirisax.rb index 8af7b5e565..38c8685390 100644 --- a/activesupport/lib/active_support/xml_mini/nokogirisax.rb +++ b/activesupport/lib/active_support/xml_mini/nokogirisax.rb @@ -1,4 +1,9 @@ -require 'nokogiri' +begin + require 'nokogiri' +rescue LoadError => e + $stderr.puts "You don't have nokogiri installed in your application. Please add it to your Gemfile and run bundle install" + raise e +end require 'active_support/core_ext/object/blank' # = XmlMini Nokogiri implementation using a SAX-based parser @@ -80,4 +85,4 @@ module ActiveSupport end end end -end \ No newline at end of file +end -- cgit v1.2.3 From f78de6864998369002a5b1906dad151b6c787c24 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sun, 1 Aug 2010 03:19:30 +0200 Subject: explains Array.wrap directly, rather by comparison with Kernel#Array which is too obscure, leaves the comparison to document the differences, and adds a comparison with the related idiom that uses the splat operator --- .../lib/active_support/core_ext/array/wrap.rb | 23 +++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/core_ext/array/wrap.rb b/activesupport/lib/active_support/core_ext/array/wrap.rb index 09a1c2e5a1..06b2acd662 100644 --- a/activesupport/lib/active_support/core_ext/array/wrap.rb +++ b/activesupport/lib/active_support/core_ext/array/wrap.rb @@ -1,5 +1,17 @@ class Array - # Array.wrap is like Kernel#Array except: + # Wraps its argument in an array unless it is already an array (or array-like). + # + # Specifically: + # + # * If the argument is +nil+ an empty list is returned. + # * Otherwise, if the argument responds to +to_ary+ it is invoked, and its result returned. + # * Otherwise, returns an array with the argument as its single element. + # + # Array.wrap(nil) # => [] + # Array.wrap([1, 2, 3]) # => [1, 2, 3] + # Array.wrap(0) # => [0] + # + # This method is similar in purpose to Kernel#Array, but there are some differences: # # * If the argument responds to +to_ary+ the method is invoked. Kernel#Array # moves on to try +to_a+ if the returned value is +nil+, but Arraw.wrap returns @@ -15,6 +27,15 @@ class Array # # Array("foo\nbar") # => ["foo\n", "bar"], in Ruby 1.8 # Array.wrap("foo\nbar") # => ["foo\nbar"] + # + # There's also a related idiom that uses the splat operator: + # + # [*object] + # + # which returns [nil] for +nil+, and calls to Array(object) otherwise. + # + # Thus, in this case the behavior is different for +nil+, and the differences with + # Kernel#Array explained above apply to the rest of +object+s. def self.wrap(object) if object.nil? [] -- cgit v1.2.3 From 59cf514a5b769257a1538736d91f48ee0900e236 Mon Sep 17 00:00:00 2001 From: Chris Hoffman Date: Fri, 23 Jul 2010 19:09:27 -0500 Subject: Add missing require in ActiveSupport::HashWithIndifferentAccess [#5189 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/hash_with_indifferent_access.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/hash_with_indifferent_access.rb b/activesupport/lib/active_support/hash_with_indifferent_access.rb index f64f0f44cc..eec5d4cf47 100644 --- a/activesupport/lib/active_support/hash_with_indifferent_access.rb +++ b/activesupport/lib/active_support/hash_with_indifferent_access.rb @@ -1,3 +1,4 @@ +require 'active_support/core_ext/hash/indifferent_access' require 'active_support/core_ext/hash/keys' # This class has dubious semantics and we only have it so that -- cgit v1.2.3 From 88b5f938cf7d3eb26ad204451a4dbb9c2cf4f571 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Mon, 2 Aug 2010 18:40:20 +0200 Subject: Bring returning back to ease migration. --- .../lib/active_support/core_ext/object.rb | 1 + .../active_support/core_ext/object/returning.rb | 43 ++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 activesupport/lib/active_support/core_ext/object/returning.rb (limited to 'activesupport') diff --git a/activesupport/lib/active_support/core_ext/object.rb b/activesupport/lib/active_support/core_ext/object.rb index 790a26f5c1..d671da6711 100644 --- a/activesupport/lib/active_support/core_ext/object.rb +++ b/activesupport/lib/active_support/core_ext/object.rb @@ -2,6 +2,7 @@ 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 new file mode 100644 index 0000000000..07250b2a27 --- /dev/null +++ b/activesupport/lib/active_support/core_ext/object/returning.rb @@ -0,0 +1,43 @@ +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 -- cgit v1.2.3 From 8bf79739b4219eb1d6464e6eb4853e92e81d7621 Mon Sep 17 00:00:00 2001 From: wycats Date: Wed, 4 Aug 2010 02:16:48 -0700 Subject: require_dependency should require using the normal mechanism if possible to avoid double-requires --- activesupport/lib/active_support/dependencies.rb | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb index 2b80bd214f..1b93eac7ee 100644 --- a/activesupport/lib/active_support/dependencies.rb +++ b/activesupport/lib/active_support/dependencies.rb @@ -276,14 +276,22 @@ module ActiveSupport #:nodoc: end def depend_on(file_name, swallow_load_errors = false, message = "No such file to load -- %s.rb") - path = search_for_file(file_name) - require_or_load(path || file_name) - rescue LoadError => load_error - unless swallow_load_errors - if file_name = load_error.message[/ -- (.*?)(\.rb)?$/, 1] - raise LoadError.new(message % file_name).copy_blame!(load_error) + #path = search_for_file(file_name) + require_or_load(file_name) + rescue LoadError + begin + if path = search_for_file(file_name) + require_or_load(path) + else + raise + end + rescue LoadError => load_error + unless swallow_load_errors + if file_name = load_error.message[/ -- (.*?)(\.rb)?$/, 1] + raise LoadError.new(message % file_name).copy_blame!(load_error) + end + raise end - raise end end -- cgit v1.2.3 From 991cd59a225b90ab1ba31867810b8fc0942713eb Mon Sep 17 00:00:00 2001 From: wycats Date: Wed, 4 Aug 2010 03:21:37 -0700 Subject: If a file is in the load path, require it without its full path (in more places) --- activesupport/lib/active_support/dependencies.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb index 1b93eac7ee..198c124292 100644 --- a/activesupport/lib/active_support/dependencies.rb +++ b/activesupport/lib/active_support/dependencies.rb @@ -388,8 +388,13 @@ module ActiveSupport #:nodoc: end # Search for a file in autoload_paths matching the provided suffix. - def search_for_file(path_suffix) - path_suffix = path_suffix.sub(/(\.rb)?$/, ".rb") + def search_for_file(file) + path_suffix = file.sub(/(\.rb)?$/, ".rb") + + $:.each do |root| + path = File.join(root, path_suffix) + return file if File.file?(path) + end autoload_paths.each do |root| path = File.join(root, path_suffix) -- cgit v1.2.3 From 462666b73717333d460684339c6f6ce07475f713 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 4 Aug 2010 14:17:00 -0300 Subject: Revert "If a file is in the load path, require it without its full path (in more places)" Caused failures in ActionMailer test suite. This reverts commit 991cd59a225b90ab1ba31867810b8fc0942713eb. --- activesupport/lib/active_support/dependencies.rb | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb index 198c124292..1b93eac7ee 100644 --- a/activesupport/lib/active_support/dependencies.rb +++ b/activesupport/lib/active_support/dependencies.rb @@ -388,13 +388,8 @@ module ActiveSupport #:nodoc: end # Search for a file in autoload_paths matching the provided suffix. - def search_for_file(file) - path_suffix = file.sub(/(\.rb)?$/, ".rb") - - $:.each do |root| - path = File.join(root, path_suffix) - return file if File.file?(path) - end + def search_for_file(path_suffix) + path_suffix = path_suffix.sub(/(\.rb)?$/, ".rb") autoload_paths.each do |root| path = File.join(root, path_suffix) -- cgit v1.2.3 From 84f0a0bc30df58e1edfd09fdde2de891e4577321 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Wed, 4 Aug 2010 18:58:18 +0200 Subject: Reload action_methods in AbstractController after defining new method. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- activesupport/lib/active_support/callbacks.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb index 1c7802f7de..0fafd56f33 100644 --- a/activesupport/lib/active_support/callbacks.rb +++ b/activesupport/lib/active_support/callbacks.rb @@ -419,7 +419,10 @@ module ActiveSupport @_keyed_callbacks ||= {} @_keyed_callbacks[name] ||= begin str = send("_#{kind}_callbacks").compile(name, object) - class_eval "def #{name}() #{str} end", __FILE__, __LINE__ + class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1 + def #{name}() #{str} end + protected :#{name} + RUBY_EVAL true end end -- cgit v1.2.3 From 589e6977d72b232b6e1af5ef508beddffbcd5f4c Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Wed, 4 Aug 2010 17:02:38 -0400 Subject: adding documentation to ActiveSupport::Concern ht:strictly typed for an awesome example some minor documentation changes --- activesupport/lib/active_support/callbacks.rb | 4 ++- activesupport/lib/active_support/concern.rb | 35 +++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb index 1c7802f7de..adabdd3388 100644 --- a/activesupport/lib/active_support/callbacks.rb +++ b/activesupport/lib/active_support/callbacks.rb @@ -568,7 +568,9 @@ module ActiveSupport # # would trigger Audit#before_save instead. That's constructed by calling # "#{kind}_#{name}" on the given instance. In this case "kind" is "before" and - # "name" is "save". + # "name" is "save". In this context treat ":kind" and ":name" as special thing where + # ":kind" refers to "callback type(before/after)" and ":name" refers to the method on + # which callbacks are being defined. # # A declaration like # diff --git a/activesupport/lib/active_support/concern.rb b/activesupport/lib/active_support/concern.rb index eb31f7cad4..408d327dd7 100644 --- a/activesupport/lib/active_support/concern.rb +++ b/activesupport/lib/active_support/concern.rb @@ -1,3 +1,38 @@ +# A typical module looks like this +# +# module M +# def self.included(base) +# base.send(:extend, ClassMethods) +# base.send(:include, InstanceMethods) +# scope :foo, :conditions => {:created_at => nil} +# end +# +# module ClassMethods +# def cm; puts 'I am class method'; end +# end +# +# module InstanceMethods +# def im; puts 'I am instance method'; end +# end +# end +# +# By using ActiveSupport::Concern above module could be written as: +# +# module M +# extend ActiveSupport::Concern +# +# included do +# scope :foo, :conditions => {:created_at => nil} +# end +# +# module ClassMethods +# def cm; puts 'I am class method'; end +# end +# +# module InstanceMethods +# def im; puts 'I am instance method'; end +# end +# end module ActiveSupport module Concern def self.extended(base) -- cgit v1.2.3 From f544c0a32dd86d4fe2c11e9111d3403fbbab2776 Mon Sep 17 00:00:00 2001 From: Tom Stuart Date: Thu, 5 Aug 2010 09:02:30 +0100 Subject: Fix ActiveSupport::Callbacks' define_callbacks and ActiveSupport::Concern documentation to look like native English --- activesupport/lib/active_support/callbacks.rb | 6 +++--- activesupport/lib/active_support/concern.rb | 16 ++++++++-------- 2 files changed, 11 insertions(+), 11 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb index adabdd3388..4950d009d1 100644 --- a/activesupport/lib/active_support/callbacks.rb +++ b/activesupport/lib/active_support/callbacks.rb @@ -568,9 +568,9 @@ module ActiveSupport # # would trigger Audit#before_save instead. That's constructed by calling # "#{kind}_#{name}" on the given instance. In this case "kind" is "before" and - # "name" is "save". In this context treat ":kind" and ":name" as special thing where - # ":kind" refers to "callback type(before/after)" and ":name" refers to the method on - # which callbacks are being defined. + # "name" is "save". In this context ":kind" and ":name" have special meanings: ":kind" + # refers to the kind of callback (before/after/around) and ":name" refers to the + # method on which callbacks are being defined. # # A declaration like # diff --git a/activesupport/lib/active_support/concern.rb b/activesupport/lib/active_support/concern.rb index 408d327dd7..2d87e8d0e5 100644 --- a/activesupport/lib/active_support/concern.rb +++ b/activesupport/lib/active_support/concern.rb @@ -4,33 +4,33 @@ # def self.included(base) # base.send(:extend, ClassMethods) # base.send(:include, InstanceMethods) -# scope :foo, :conditions => {:created_at => nil} +# scope :foo, :conditions => { :created_at => nil } # end # # module ClassMethods -# def cm; puts 'I am class method'; end +# def cm; puts 'I am a class method'; end # end # # module InstanceMethods -# def im; puts 'I am instance method'; end +# def im; puts 'I am an instance method'; end # end # end # -# By using ActiveSupport::Concern above module could be written as: +# By using ActiveSupport::Concern the above module could instead be written as: # # module M # extend ActiveSupport::Concern # -# included do -# scope :foo, :conditions => {:created_at => nil} +# included do +# scope :foo, :conditions => { :created_at => nil } # end # # module ClassMethods -# def cm; puts 'I am class method'; end +# def cm; puts 'I am a class method'; end # end # # module InstanceMethods -# def im; puts 'I am instance method'; end +# def im; puts 'I am an instance method'; end # end # end module ActiveSupport -- cgit v1.2.3 From 8a657c0dc7e914111521eab1b0e69c20e57a8b3d Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Thu, 5 Aug 2010 16:11:11 +0200 Subject: adds test coverage to ensure DateTime#advance processes first the date deltas, and then the time deltas --- activesupport/test/core_ext/date_time_ext_test.rb | 31 ++++++++++++++--------- 1 file changed, 19 insertions(+), 12 deletions(-) (limited to 'activesupport') diff --git a/activesupport/test/core_ext/date_time_ext_test.rb b/activesupport/test/core_ext/date_time_ext_test.rb index 19d7935211..e8506f5222 100644 --- a/activesupport/test/core_ext/date_time_ext_test.rb +++ b/activesupport/test/core_ext/date_time_ext_test.rb @@ -171,22 +171,29 @@ class DateTimeExtCalculationsTest < Test::Unit::TestCase end def test_advance - assert_equal DateTime.civil(2006,2,28,15,15,10), DateTime.civil(2005,2,28,15,15,10).advance(:years => 1) - assert_equal DateTime.civil(2005,6,28,15,15,10), DateTime.civil(2005,2,28,15,15,10).advance(:months => 4) - assert_equal DateTime.civil(2005,3,21,15,15,10), DateTime.civil(2005,2,28,15,15,10).advance(:weeks => 3) - assert_equal DateTime.civil(2005,3,5,15,15,10), DateTime.civil(2005,2,28,15,15,10).advance(:days => 5) - assert_equal DateTime.civil(2012,9,28,15,15,10), DateTime.civil(2005,2,28,15,15,10).advance(:years => 7, :months => 7) - assert_equal DateTime.civil(2013,10,3,15,15,10), DateTime.civil(2005,2,28,15,15,10).advance(:years => 7, :months => 19, :days => 5) + assert_equal DateTime.civil(2006,2,28,15,15,10), DateTime.civil(2005,2,28,15,15,10).advance(:years => 1) + assert_equal DateTime.civil(2005,6,28,15,15,10), DateTime.civil(2005,2,28,15,15,10).advance(:months => 4) + assert_equal DateTime.civil(2005,3,21,15,15,10), DateTime.civil(2005,2,28,15,15,10).advance(:weeks => 3) + assert_equal DateTime.civil(2005,3,5,15,15,10), DateTime.civil(2005,2,28,15,15,10).advance(:days => 5) + assert_equal DateTime.civil(2012,9,28,15,15,10), DateTime.civil(2005,2,28,15,15,10).advance(:years => 7, :months => 7) + assert_equal DateTime.civil(2013,10,3,15,15,10), DateTime.civil(2005,2,28,15,15,10).advance(:years => 7, :months => 19, :days => 5) assert_equal DateTime.civil(2013,10,17,15,15,10), DateTime.civil(2005,2,28,15,15,10).advance(:years => 7, :months => 19, :weeks => 2, :days => 5) assert_equal DateTime.civil(2001,12,27,15,15,10), DateTime.civil(2005,2,28,15,15,10).advance(:years => -3, :months => -2, :days => -1) - assert_equal DateTime.civil(2005,2,28,15,15,10), DateTime.civil(2004,2,29,15,15,10).advance(:years => 1) #leap day plus one year - assert_equal DateTime.civil(2005,2,28,20,15,10), DateTime.civil(2005,2,28,15,15,10).advance(:hours => 5) - assert_equal DateTime.civil(2005,2,28,15,22,10), DateTime.civil(2005,2,28,15,15,10).advance(:minutes => 7) - assert_equal DateTime.civil(2005,2,28,15,15,19), DateTime.civil(2005,2,28,15,15,10).advance(:seconds => 9) - assert_equal DateTime.civil(2005,2,28,20,22,19), DateTime.civil(2005,2,28,15,15,10).advance(:hours => 5, :minutes => 7, :seconds => 9) - assert_equal DateTime.civil(2005,2,28,10,8,1), DateTime.civil(2005,2,28,15,15,10).advance(:hours => -5, :minutes => -7, :seconds => -9) + assert_equal DateTime.civil(2005,2,28,15,15,10), DateTime.civil(2004,2,29,15,15,10).advance(:years => 1) #leap day plus one year + assert_equal DateTime.civil(2005,2,28,20,15,10), DateTime.civil(2005,2,28,15,15,10).advance(:hours => 5) + assert_equal DateTime.civil(2005,2,28,15,22,10), DateTime.civil(2005,2,28,15,15,10).advance(:minutes => 7) + assert_equal DateTime.civil(2005,2,28,15,15,19), DateTime.civil(2005,2,28,15,15,10).advance(:seconds => 9) + assert_equal DateTime.civil(2005,2,28,20,22,19), DateTime.civil(2005,2,28,15,15,10).advance(:hours => 5, :minutes => 7, :seconds => 9) + assert_equal DateTime.civil(2005,2,28,10,8,1), DateTime.civil(2005,2,28,15,15,10).advance(:hours => -5, :minutes => -7, :seconds => -9) assert_equal DateTime.civil(2013,10,17,20,22,19), DateTime.civil(2005,2,28,15,15,10).advance(:years => 7, :months => 19, :weeks => 2, :days => 5, :hours => 5, :minutes => 7, :seconds => 9) + end + def test_advanced_processes_first_the_date_deltas_and_then_the_time_deltas + # If the time deltas were processed first, the following datetimes would be advanced to 2010/04/01 instead. + assert_equal DateTime.civil(2010, 3, 29), DateTime.civil(2010, 2, 28, 23, 59, 59).advance(:months => 1, :seconds => 1) + assert_equal DateTime.civil(2010, 3, 29), DateTime.civil(2010, 2, 28, 23, 59).advance(:months => 1, :minutes => 1) + assert_equal DateTime.civil(2010, 3, 29), DateTime.civil(2010, 2, 28, 23).advance(:months => 1, :hours => 1) + assert_equal DateTime.civil(2010, 3, 29), DateTime.civil(2010, 2, 28, 22, 58, 59).advance(:months => 1, :hours => 1, :minutes => 1, :seconds => 1) end def test_next_week -- cgit v1.2.3 From cd87cf771acb90c43cd56e5f038fc345a69790f9 Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Thu, 5 Aug 2010 11:54:46 -0400 Subject: correcting the documentation that default to false. it does not default to false. returing either false or nil will not halt the chain unless :terminator is explicitly mentioned --- activesupport/lib/active_support/callbacks.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb index 4950d009d1..e179287b24 100644 --- a/activesupport/lib/active_support/callbacks.rb +++ b/activesupport/lib/active_support/callbacks.rb @@ -522,14 +522,13 @@ module ActiveSupport # # This macro accepts the following options: # - # * :terminator - Indicates when a before filter is considered - # to be halted. + # * :terminator - Indicates when a before filter is considered to be halted. # # define_callbacks :validate, :terminator => "result == false" # - # In the example above, if any before validate callbacks returns +false+, - # other callbacks are not executed. Defaults to "false", meaning no value - # halts the chain. + # In the example above, if any before validate callback returns +false+, + # other callbacks are not executed. Note that in this case if the callback + # returns +nil+ then other callbacks are still executed. # # * :rescuable - By default, after filters are not executed if # the given block or a before filter raises an error. Set this option to -- cgit v1.2.3 From 5130b0cf45e5efa93f60d34ae8bae02f67a4fec2 Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Thu, 5 Aug 2010 11:55:20 -0400 Subject: more documentation for class_inheritable_* --- .../core_ext/class/inheritable_attributes.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/core_ext/class/inheritable_attributes.rb b/activesupport/lib/active_support/core_ext/class/inheritable_attributes.rb index 92d6dbadd4..a33c772482 100644 --- a/activesupport/lib/active_support/core_ext/class/inheritable_attributes.rb +++ b/activesupport/lib/active_support/core_ext/class/inheritable_attributes.rb @@ -5,6 +5,10 @@ require 'active_support/core_ext/array/extract_options' module ClassInheritableAttributes # :nodoc: end +# It is recommend to use class_attribute over methods defined in this file. Please +# refer to documentation for class_attribute for more infor. Officially it is not +# deprected but class_attribute is faster. +# # Allows attributes to be shared within an inheritance hierarchy. Each descendant gets a copy of # their parents' attributes, instead of just a pointer to the same. This means that the child can add elements # to, for example, an array without those additions being shared with either their parent, siblings, or @@ -12,6 +16,24 @@ end # # The copies of inheritable parent attributes are added to subclasses when they are created, via the # +inherited+ hook. +# +# class Person +# class_inheritable_accessor :hair_colors +# end +# +# Person.hair_colors = [:brown, :black, :blonde, :red] +# Person.hair_colors #=> [:brown, :black, :blonde, :red] +# Person.new.hair_colors #=> [:brown, :black, :blonde, :red] +# +# To opt out of the instance writer method, pass :instance_writer => false. +# To opt out of the instance reader method, pass :instance_reader => false. +# +# class Person +# cattr_accessor :hair_colors :instance_writer => false, :instance_reader => false +# end +# +# Person.new.hair_colors = [:brown] # => NoMethodError +# Person.new.hair_colors # => NoMethodError class Class # :nodoc: def class_inheritable_reader(*syms) options = syms.extract_options! -- cgit v1.2.3 From 86842fd1ce2dd4dac75f1a05ece646eab80c9347 Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Thu, 5 Aug 2010 16:35:40 -0400 Subject: fixing typo --- .../lib/active_support/core_ext/class/inheritable_attributes.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/core_ext/class/inheritable_attributes.rb b/activesupport/lib/active_support/core_ext/class/inheritable_attributes.rb index a33c772482..d7a30cf123 100644 --- a/activesupport/lib/active_support/core_ext/class/inheritable_attributes.rb +++ b/activesupport/lib/active_support/core_ext/class/inheritable_attributes.rb @@ -6,7 +6,7 @@ module ClassInheritableAttributes # :nodoc: end # It is recommend to use class_attribute over methods defined in this file. Please -# refer to documentation for class_attribute for more infor. Officially it is not +# refer to documentation for class_attribute for more information. Officially it is not # deprected but class_attribute is faster. # # Allows attributes to be shared within an inheritance hierarchy. Each descendant gets a copy of -- cgit v1.2.3 From 232218f46533a4f2512d522dc7c730eaf4cedd82 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Thu, 5 Aug 2010 22:46:04 +0200 Subject: Revert "correcting the documentation that default to false. it does not default to false. returing either false or nil will not halt the chain unless :terminator is explicitly mentioned" This reverts commit cd87cf771acb90c43cd56e5f038fc345a69790f9. Reason: it does default to "false". --- activesupport/lib/active_support/callbacks.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb index e179287b24..4950d009d1 100644 --- a/activesupport/lib/active_support/callbacks.rb +++ b/activesupport/lib/active_support/callbacks.rb @@ -522,13 +522,14 @@ module ActiveSupport # # This macro accepts the following options: # - # * :terminator - Indicates when a before filter is considered to be halted. + # * :terminator - Indicates when a before filter is considered + # to be halted. # # define_callbacks :validate, :terminator => "result == false" # - # In the example above, if any before validate callback returns +false+, - # other callbacks are not executed. Note that in this case if the callback - # returns +nil+ then other callbacks are still executed. + # In the example above, if any before validate callbacks returns +false+, + # other callbacks are not executed. Defaults to "false", meaning no value + # halts the chain. # # * :rescuable - By default, after filters are not executed if # the given block or a before filter raises an error. Set this option to -- cgit v1.2.3 From 02e711bf1c2afe13a84ded3167bb633dcb4f8cb7 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Thu, 5 Aug 2010 22:54:43 +0200 Subject: documents that :terminator is a string to be eval'ed, and that it sees the result variable --- activesupport/lib/active_support/callbacks.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb index 4950d009d1..5e0c5b6e98 100644 --- a/activesupport/lib/active_support/callbacks.rb +++ b/activesupport/lib/active_support/callbacks.rb @@ -523,7 +523,8 @@ module ActiveSupport # This macro accepts the following options: # # * :terminator - Indicates when a before filter is considered - # to be halted. + # to halted. This is a string to be eval'ed and has the result of the + # very filter available in the result variable: # # define_callbacks :validate, :terminator => "result == false" # -- cgit v1.2.3 From d0ac56b5b4194bdf36bbd3b49ad64649b0675c66 Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Thu, 5 Aug 2010 16:57:20 -0400 Subject: adding an example of skipping a callback --- activesupport/lib/active_support/callbacks.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb index 7290c971f9..24e407c253 100644 --- a/activesupport/lib/active_support/callbacks.rb +++ b/activesupport/lib/active_support/callbacks.rb @@ -486,7 +486,11 @@ module ActiveSupport end end - # Skip a previously defined callback for a given type. + # Skip a previously defined callback. + # + # class Writer < Person + # skip_callback :validate, :before, :check_membership, :if => lambda { self.age > 18 } + # end # def skip_callback(name, *filter_list, &block) __update_callbacks(name, filter_list, block) do |chain, type, filters, options| -- cgit v1.2.3 From cdbc880055fba8bfa63b2c3c5fda94c48f87b037 Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Fri, 6 Aug 2010 01:50:54 -0400 Subject: adding documentation for OrderedHash and OrderedOptions --- activesupport/lib/active_support/ordered_hash.rb | 9 ++++++++- activesupport/lib/active_support/ordered_options.rb | 16 ++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/ordered_hash.rb b/activesupport/lib/active_support/ordered_hash.rb index 6b563b9063..e19d9d7dc1 100644 --- a/activesupport/lib/active_support/ordered_hash.rb +++ b/activesupport/lib/active_support/ordered_hash.rb @@ -4,7 +4,14 @@ YAML.add_builtin_type("omap") do |type, val| ActiveSupport::OrderedHash[val.map(&:to_a).map(&:first)] end -# OrderedHash is namespaced to prevent conflicts with other implementations +# Hash is not ordered in ruby 1.8.x. What it means is there is no guarantee of order of keys when +# method Hash#keys in invoked. Similarly Hash#values and Hash#each can't guarantee that each time +# the output will contain exactly same value in the same order. OrderedHash solves that +# problem. +# +# ActiveSupport::OrderedHash[:boy, 'John', :girl, 'Mary'] +# +# OrderedHash is namespaced to prevent conflicts with other implementations. module ActiveSupport class OrderedHash < ::Hash #:nodoc: def to_yaml_type diff --git a/activesupport/lib/active_support/ordered_options.rb b/activesupport/lib/active_support/ordered_options.rb index 61ccb79211..b0584072c1 100644 --- a/activesupport/lib/active_support/ordered_options.rb +++ b/activesupport/lib/active_support/ordered_options.rb @@ -1,5 +1,21 @@ require 'active_support/ordered_hash' +# Usually key value pairs are handled something like this: +# +# h = ActiveSupport::OrderedOptions.new +# h[:boy] = 'John' +# h[:girl] = 'Mary' +# h[:boy] #=> 'John' +# h[:girl] #=> 'Mary' +# +# Using OrderedOptions above code could be reduced to: +# +# h = ActiveSupport::OrderedOptions.new +# h.boy = 'John' +# h.girl = 'Mary' +# h.boy #=> 'John' +# h.girl #=> 'Mary' +# module ActiveSupport #:nodoc: class OrderedOptions < OrderedHash def []=(key, value) -- cgit v1.2.3 From e0a0638094192061b5537f776a6a250b85cb09b8 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Fri, 6 Aug 2010 13:11:44 +0200 Subject: commit review: say clearly that AS::OrderedHash is about insertion order, be more neutral in wording, do not imply lack of ordering is a problem --- activesupport/lib/active_support/ordered_hash.rb | 18 ++++++++++-------- activesupport/lib/active_support/ordered_options.rb | 8 ++++---- 2 files changed, 14 insertions(+), 12 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/ordered_hash.rb b/activesupport/lib/active_support/ordered_hash.rb index e19d9d7dc1..2e8d538d0b 100644 --- a/activesupport/lib/active_support/ordered_hash.rb +++ b/activesupport/lib/active_support/ordered_hash.rb @@ -4,15 +4,17 @@ YAML.add_builtin_type("omap") do |type, val| ActiveSupport::OrderedHash[val.map(&:to_a).map(&:first)] end -# Hash is not ordered in ruby 1.8.x. What it means is there is no guarantee of order of keys when -# method Hash#keys in invoked. Similarly Hash#values and Hash#each can't guarantee that each time -# the output will contain exactly same value in the same order. OrderedHash solves that -# problem. -# -# ActiveSupport::OrderedHash[:boy, 'John', :girl, 'Mary'] -# -# OrderedHash is namespaced to prevent conflicts with other implementations. module ActiveSupport + # The order of iteration over hashes in Ruby 1.8 is undefined. For example, you do not know the + # order in which +keys+ will return keys, or +each+ yield pairs. ActiveSupport::OrderedHash + # implements a hash that preserves insertion order, as in Ruby 1.9: + # + # oh = ActiveSupport::OrderedHash.new + # oh[:a] = 1 + # oh[:b] = 2 + # oh.keys # => [:a, :b], this order is guaranteed + # + # ActiveSupport::OrderedHash is namespaced to prevent conflicts with other implementations. class OrderedHash < ::Hash #:nodoc: def to_yaml_type "!tag:yaml.org,2002:omap" diff --git a/activesupport/lib/active_support/ordered_options.rb b/activesupport/lib/active_support/ordered_options.rb index b0584072c1..7fc2b45b51 100644 --- a/activesupport/lib/active_support/ordered_options.rb +++ b/activesupport/lib/active_support/ordered_options.rb @@ -5,16 +5,16 @@ require 'active_support/ordered_hash' # h = ActiveSupport::OrderedOptions.new # h[:boy] = 'John' # h[:girl] = 'Mary' -# h[:boy] #=> 'John' -# h[:girl] #=> 'Mary' +# h[:boy] # => 'John' +# h[:girl] # => 'Mary' # # Using OrderedOptions above code could be reduced to: # # h = ActiveSupport::OrderedOptions.new # h.boy = 'John' # h.girl = 'Mary' -# h.boy #=> 'John' -# h.girl #=> 'Mary' +# h.boy # => 'John' +# h.girl # => 'Mary' # module ActiveSupport #:nodoc: class OrderedOptions < OrderedHash -- cgit v1.2.3 From fc01adee79cd38069d89c2e457be99911e2a0ea3 Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Fri, 6 Aug 2010 15:51:52 -0400 Subject: correcting wrong example --- .../lib/active_support/core_ext/class/inheritable_attributes.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/core_ext/class/inheritable_attributes.rb b/activesupport/lib/active_support/core_ext/class/inheritable_attributes.rb index d7a30cf123..e844cf50d1 100644 --- a/activesupport/lib/active_support/core_ext/class/inheritable_attributes.rb +++ b/activesupport/lib/active_support/core_ext/class/inheritable_attributes.rb @@ -29,7 +29,7 @@ end # To opt out of the instance reader method, pass :instance_reader => false. # # class Person -# cattr_accessor :hair_colors :instance_writer => false, :instance_reader => false +# class_inheritable_accessor :hair_colors :instance_writer => false, :instance_reader => false # end # # Person.new.hair_colors = [:brown] # => NoMethodError -- cgit v1.2.3 From e86cced311539932420f9cda49d736606d106c28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 10 Aug 2010 11:18:58 -0300 Subject: Revert "require_dependency should require using the normal mechanism if possible to avoid double-requires" This was causing double requires since 991cd59a225b90ab1ba3 was reverted. This reverts commit 8bf79739b4219eb1d6464e6eb4853e92e81d7621. --- activesupport/lib/active_support/dependencies.rb | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb index 1b93eac7ee..2b80bd214f 100644 --- a/activesupport/lib/active_support/dependencies.rb +++ b/activesupport/lib/active_support/dependencies.rb @@ -276,22 +276,14 @@ module ActiveSupport #:nodoc: end def depend_on(file_name, swallow_load_errors = false, message = "No such file to load -- %s.rb") - #path = search_for_file(file_name) - require_or_load(file_name) - rescue LoadError - begin - if path = search_for_file(file_name) - require_or_load(path) - else - raise - end - rescue LoadError => load_error - unless swallow_load_errors - if file_name = load_error.message[/ -- (.*?)(\.rb)?$/, 1] - raise LoadError.new(message % file_name).copy_blame!(load_error) - end - raise + path = search_for_file(file_name) + require_or_load(path || file_name) + rescue LoadError => load_error + unless swallow_load_errors + if file_name = load_error.message[/ -- (.*?)(\.rb)?$/, 1] + raise LoadError.new(message % file_name).copy_blame!(load_error) end + raise end end -- cgit v1.2.3