aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext
diff options
context:
space:
mode:
authorCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2012-03-16 00:54:39 -0300
committerCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2012-03-16 09:01:48 -0300
commitc045eebd5d35259e65771de159966b7c20690d34 (patch)
tree7bac04c81569b7d6b462892e395bb7c105245750 /activesupport/lib/active_support/core_ext
parent2afe12f05ca870437c08dfce8d9e2afb02f8b347 (diff)
downloadrails-c045eebd5d35259e65771de159966b7c20690d34.tar.gz
rails-c045eebd5d35259e65771de159966b7c20690d34.tar.bz2
rails-c045eebd5d35259e65771de159966b7c20690d34.zip
Remove deprecation from AS::Deprecation behavior, some minor cleanups
* Refactor log subscriber, use select! to avoid a new object * Remove deprecation messages related to AS::Deprecation behavior This was added about 2 years ago for Rails 3: https://github.com/rails/rails/commit/d4c7d3fd94e5a885a6366eaeb3b908bb58ffd4db * Remove some not used requires * Refactor delegate to avoid string conversions and if statements inside each block
Diffstat (limited to 'activesupport/lib/active_support/core_ext')
-rw-r--r--activesupport/lib/active_support/core_ext/module/delegation.rb16
1 files changed, 9 insertions, 7 deletions
diff --git a/activesupport/lib/active_support/core_ext/module/delegation.rb b/activesupport/lib/active_support/core_ext/module/delegation.rb
index ac2a63d3a1..af92b869fd 100644
--- a/activesupport/lib/active_support/core_ext/module/delegation.rb
+++ b/activesupport/lib/active_support/core_ext/module/delegation.rb
@@ -106,9 +106,11 @@ class Module
unless options.is_a?(Hash) && to = options[:to]
raise ArgumentError, "Delegation needs a target. Supply an options hash with a :to key as the last argument (e.g. delegate :hello, :to => :greeter)."
end
- prefix, to, allow_nil = options[:prefix], options[:to], options[:allow_nil]
- if prefix == true && to.to_s =~ /^[^a-z_]/
+ to = to.to_s
+ prefix, allow_nil = options.values_at(:prefix, :allow_nil)
+
+ if prefix == true && to =~ /^[^a-z_]/
raise ArgumentError, "Can only automatically set the delegation prefix when delegating to a method."
end
@@ -122,10 +124,8 @@ class Module
file, line = caller.first.split(':', 2)
line = line.to_i
- methods.each do |method|
- method = method.to_s
-
- if allow_nil
+ if allow_nil
+ methods.each do |method|
module_eval(<<-EOS, file, line - 2)
def #{method_prefix}#{method}(*args, &block) # def customer_name(*args, &block)
if #{to} || #{to}.respond_to?(:#{method}) # if client || client.respond_to?(:name)
@@ -133,7 +133,9 @@ class Module
end # end
end # end
EOS
- else
+ end
+ else
+ methods.each do |method|
exception = %(raise "#{self}##{method_prefix}#{method} delegated to #{to}.#{method}, but #{to} is nil: \#{self.inspect}")
module_eval(<<-EOS, file, line - 1)