aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/callbacks.rb
diff options
context:
space:
mode:
authorSantiago Pastorino <santiago@wyeworks.com>2010-05-19 16:37:41 -0300
committerJosé Valim <jose.valim@gmail.com>2010-05-20 15:18:57 +0200
commitaacf2581cde0147dc66c3eeacf6d7447c2bbafdf (patch)
treea7f099044c0e8678454af5852a415c757c567c94 /activesupport/lib/active_support/callbacks.rb
parent7f07cc364a7ee7ceae21b29b54467fde0db93389 (diff)
downloadrails-aacf2581cde0147dc66c3eeacf6d7447c2bbafdf.tar.gz
rails-aacf2581cde0147dc66c3eeacf6d7447c2bbafdf.tar.bz2
rails-aacf2581cde0147dc66c3eeacf6d7447c2bbafdf.zip
refactor evals and adds some __FILE__ and __LINE__
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'activesupport/lib/active_support/callbacks.rb')
-rw-r--r--activesupport/lib/active_support/callbacks.rb51
1 files changed, 24 insertions, 27 deletions
diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb
index 5a7b94ead7..933667c909 100644
--- a/activesupport/lib/active_support/callbacks.rb
+++ b/activesupport/lib/active_support/callbacks.rb
@@ -203,8 +203,8 @@ module ActiveSupport
# end
#
name = "_conditional_callback_#{@kind}_#{next_id}"
- txt, line = <<-RUBY_EVAL, __LINE__ + 1
- def #{name}(halted)
+ @klass.class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
+ def #{name}(halted)
#{@compiled_options[0] || "if true"} && !halted
#{@filter} do
yield self
@@ -214,7 +214,6 @@ module ActiveSupport
end
end
RUBY_EVAL
- @klass.class_eval(txt, __FILE__, line)
"#{name}(halted) do"
end
end
@@ -312,9 +311,9 @@ module ActiveSupport
def _normalize_legacy_filter(kind, filter)
if !filter.respond_to?(kind) && filter.respond_to?(:filter)
- filter.singleton_class.class_eval(
- "def #{kind}(context, &block) filter(context, &block) end",
- __FILE__, __LINE__ - 1)
+ filter.singleton_class.class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
+ def #{kind}(context, &block) filter(context, &block) end
+ RUBY_EVAL
elsif filter.respond_to?(:before) && filter.respond_to?(:after) && kind == :around
def filter.around(context)
should_continue = before(context)
@@ -387,31 +386,29 @@ module ActiveSupport
send("_update_#{symbol}_superclass_callbacks")
body = send("_#{symbol}_callbacks").compile(nil)
- body, line = <<-RUBY_EVAL, __LINE__ + 1
- def _run_#{symbol}_callbacks(key = nil, &blk)
- if self.class.send("_update_#{symbol}_superclass_callbacks")
- self.class.__define_runner(#{symbol.inspect})
- return _run_#{symbol}_callbacks(key, &blk)
- end
+ silence_warnings do
+ undef_method "_run_#{symbol}_callbacks" if method_defined?("_run_#{symbol}_callbacks")
+ class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
+ def _run_#{symbol}_callbacks(key = nil, &blk)
+ if self.class.send("_update_#{symbol}_superclass_callbacks")
+ self.class.__define_runner(#{symbol.inspect})
+ return _run_#{symbol}_callbacks(key, &blk)
+ end
- if key
- name = "_run__\#{self.class.name.hash.abs}__#{symbol}__\#{key.hash.abs}__callbacks"
+ if key
+ name = "_run__\#{self.class.name.hash.abs}__#{symbol}__\#{key.hash.abs}__callbacks"
- unless respond_to?(name)
- self.class.__create_keyed_callback(name, :#{symbol}, self, &blk)
- end
+ unless respond_to?(name)
+ self.class.__create_keyed_callback(name, :#{symbol}, self, &blk)
+ end
- send(name, &blk)
- else
- #{body}
+ send(name, &blk)
+ else
+ #{body}
+ end
end
- end
- private :_run_#{symbol}_callbacks
- RUBY_EVAL
-
- silence_warnings do
- undef_method "_run_#{symbol}_callbacks" if method_defined?("_run_#{symbol}_callbacks")
- class_eval body, __FILE__, line
+ private :_run_#{symbol}_callbacks
+ RUBY_EVAL
end
end