aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r--activesupport/lib/active_support/core_ext/hash/conversions.rb2
-rw-r--r--activesupport/lib/active_support/core_ext/kernel/requires.rb4
-rw-r--r--activesupport/lib/active_support/core_ext/object.rb2
-rw-r--r--activesupport/lib/active_support/core_ext/object/misc.rb2
-rw-r--r--activesupport/lib/active_support/core_ext/object/returning.rb42
-rw-r--r--activesupport/lib/active_support/dependencies.rb2
-rw-r--r--activesupport/lib/active_support/descendants_tracker.rb8
-rw-r--r--activesupport/lib/active_support/json/backends/yaml.rb2
-rw-r--r--activesupport/lib/active_support/multibyte/unicode.rb11
-rw-r--r--activesupport/lib/active_support/notifications.rb24
-rw-r--r--activesupport/lib/active_support/notifications/fanout.rb11
-rw-r--r--activesupport/lib/active_support/notifications/instrumenter.rb14
-rw-r--r--activesupport/lib/active_support/testing/setup_and_teardown.rb2
-rw-r--r--activesupport/lib/active_support/xml_mini/libxml.rb1
14 files changed, 49 insertions, 78 deletions
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
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/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/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/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
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/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..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(payload) if block_given?
+ 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/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/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