diff options
author | Santiago Pastorino <santiago@wyeworks.com> | 2010-05-19 16:37:41 -0300 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-05-20 15:18:57 +0200 |
commit | aacf2581cde0147dc66c3eeacf6d7447c2bbafdf (patch) | |
tree | a7f099044c0e8678454af5852a415c757c567c94 | |
parent | 7f07cc364a7ee7ceae21b29b54467fde0db93389 (diff) | |
download | rails-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>
17 files changed, 53 insertions, 60 deletions
diff --git a/actionpack/lib/abstract_controller/layouts.rb b/actionpack/lib/abstract_controller/layouts.rb index 319472c937..5cd7a90ab5 100644 --- a/actionpack/lib/abstract_controller/layouts.rb +++ b/actionpack/lib/abstract_controller/layouts.rb @@ -245,7 +245,7 @@ module AbstractController case defined?(@_layout) ? @_layout : nil when String - self.class_eval %{def _layout; #{@_layout.inspect} end} + self.class_eval %{def _layout; #{@_layout.inspect} end}, __FILE__, __LINE__ when Symbol self.class_eval <<-ruby_eval, __FILE__, __LINE__ + 1 def _layout @@ -259,9 +259,9 @@ module AbstractController ruby_eval when Proc define_method :_layout_from_proc, &@_layout - self.class_eval %{def _layout; _layout_from_proc(self) end} + self.class_eval %{def _layout; _layout_from_proc(self) end}, __FILE__, __LINE__ when false - self.class_eval %{def _layout; end} + self.class_eval %{def _layout; end}, __FILE__, __LINE__ when true raise ArgumentError, "Layouts must be specified as a String, Symbol, false, or nil" when nil diff --git a/actionpack/lib/action_view/helpers/active_model_helper.rb b/actionpack/lib/action_view/helpers/active_model_helper.rb index d9f09b5dc5..0cddd09eb0 100644 --- a/actionpack/lib/action_view/helpers/active_model_helper.rb +++ b/actionpack/lib/action_view/helpers/active_model_helper.rb @@ -43,7 +43,7 @@ module ActionView end %w(tag content_tag to_date_select_tag to_datetime_select_tag to_time_select_tag).each do |meth| - module_eval "def #{meth}(*) error_wrapping(super) end" + module_eval "def #{meth}(*) error_wrapping(super) end", __FILE__, __LINE__ end def error_wrapping(html_tag) diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index 414a5d4cd9..b3db3151d3 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -1111,7 +1111,7 @@ module ActionView end (field_helpers - %w(label check_box radio_button fields_for hidden_field)).each do |selector| - src, line = <<-end_src, __LINE__ + 1 + class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1 def #{selector}(method, options = {}) # def text_field(method, options = {}) @template.send( # @template.send( #{selector.inspect}, # "text_field", @@ -1119,8 +1119,7 @@ module ActionView method, # method, objectify_options(options)) # objectify_options(options)) end # end - end_src - class_eval src, __FILE__, line + RUBY_EVAL end def fields_for(record_or_name_or_array, *args, &block) diff --git a/actionpack/lib/action_view/test_case.rb b/actionpack/lib/action_view/test_case.rb index f6417d5c2c..5517a56fb9 100644 --- a/actionpack/lib/action_view/test_case.rb +++ b/actionpack/lib/action_view/test_case.rb @@ -82,7 +82,7 @@ module ActionView def helper_method(*methods) # Almost a duplicate from ActionController::Helpers methods.flatten.each do |method| - _helpers.module_eval <<-end_eval + _helpers.module_eval <<-end_eval, __FILE__, __LINE__ + 1 def #{method}(*args, &block) # def current_user(*args, &block) _test_case.send(%(#{method}), *args, &block) # test_case.send(%(current_user), *args, &block) end # end diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index d1e1338a17..2f3869994c 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -1425,12 +1425,11 @@ class FormHelperTest < ActionView::TestCase class LabelledFormBuilder < ActionView::Helpers::FormBuilder (field_helpers - %w(hidden_field)).each do |selector| - src, line = <<-END_SRC, __LINE__ + 1 + class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1 def #{selector}(field, *args, &proc) ("<label for='\#{field}'>\#{field.to_s.humanize}:</label> " + super + "<br/>").html_safe end - END_SRC - class_eval src, __FILE__, line + RUBY_EVAL end end diff --git a/activerecord/lib/active_record/association_preload.rb b/activerecord/lib/active_record/association_preload.rb index 95bbaf00cf..1f5217191c 100644 --- a/activerecord/lib/active_record/association_preload.rb +++ b/activerecord/lib/active_record/association_preload.rb @@ -378,7 +378,7 @@ module ActiveRecord def interpolate_sql_for_preload(sql) - instance_eval("%@#{sql.gsub('@', '\@')}@") + instance_eval("%@#{sql.gsub('@', '\@')}@", __FILE__, __LINE__) end def append_conditions(reflection, preload_options) diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index f23d881c7b..5b0ba86308 100755 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -1461,7 +1461,7 @@ module ActiveRecord before_destroy(method_name) module_eval( - "#{reflection.class_name}.send(:attr_readonly,\"#{cache_column}\".intern) if defined?(#{reflection.class_name}) && #{reflection.class_name}.respond_to?(:attr_readonly)" + "#{reflection.class_name}.send(:attr_readonly,\"#{cache_column}\".intern) if defined?(#{reflection.class_name}) && #{reflection.class_name}.respond_to?(:attr_readonly)", __FILE__, __LINE__ ) end @@ -2130,7 +2130,7 @@ module ActiveRecord end def interpolate_sql(sql) - instance_eval("%@#{sql.gsub('@', '\@')}@") + instance_eval("%@#{sql.gsub('@', '\@')}@", __FILE__, __LINE__) end end end diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 1b76f357e3..aa2826fb33 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -1786,7 +1786,7 @@ module ActiveRecord #:nodoc: # Interpolate custom SQL string in instance context. # Optional record argument is meant for custom insert_sql. def interpolate_sql(sql, record = nil) - instance_eval("%@#{sql.gsub('@', '\@')}@") + instance_eval("%@#{sql.gsub('@', '\@')}@", __FILE__, __LINE__) end # Instantiates objects for all attribute classes that needs more than one constructor parameter. This is done diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb index b976844c1c..6397fbc280 100644 --- a/activeresource/lib/active_resource/base.rb +++ b/activeresource/lib/active_resource/base.rb @@ -582,12 +582,13 @@ module ActiveResource # Clear prefix parameters in case they have been cached @prefix_parameters = nil - # Redefine the new methods. - code, line = <<-end_code, __LINE__ + 1 - def prefix_source() "#{value}" end - def prefix(options={}) "#{prefix_call}" end - end_code - silence_warnings { instance_eval code, __FILE__, line } + silence_warnings do + # Redefine the new methods. + instance_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1 + def prefix_source() "#{value}" end + def prefix(options={}) "#{prefix_call}" end + RUBY_EVAL + end rescue logger.error "Couldn't set prefix: #{$!}\n #{code}" if logger raise 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 diff --git a/activesupport/lib/active_support/core_ext/class/attribute.rb b/activesupport/lib/active_support/core_ext/class/attribute.rb index d2bcd7a778..576366e496 100644 --- a/activesupport/lib/active_support/core_ext/class/attribute.rb +++ b/activesupport/lib/active_support/core_ext/class/attribute.rb @@ -61,10 +61,7 @@ class Class end RUBY - if instance_writer - body = "def #{name}=(value) @#{name} = value end" - class_eval body, __FILE__, __LINE__ - 1 - end + attr_writer name if instance_writer end end end diff --git a/activesupport/lib/active_support/core_ext/module/attr_internal.rb b/activesupport/lib/active_support/core_ext/module/attr_internal.rb index d052bfed2d..28bc30ae26 100644 --- a/activesupport/lib/active_support/core_ext/module/attr_internal.rb +++ b/activesupport/lib/active_support/core_ext/module/attr_internal.rb @@ -2,14 +2,14 @@ class Module # Declares an attribute reader backed by an internally-named instance variable. def attr_internal_reader(*attrs) attrs.each do |attr| - module_eval "def #{attr}() #{attr_internal_ivar_name(attr)} end" + module_eval "def #{attr}() #{attr_internal_ivar_name(attr)} end", __FILE__, __LINE__ end end # Declares an attribute writer backed by an internally-named instance variable. def attr_internal_writer(*attrs) attrs.each do |attr| - module_eval "def #{attr}=(v) #{attr_internal_ivar_name(attr)} = v end" + module_eval "def #{attr}=(v) #{attr_internal_ivar_name(attr)} = v end", __FILE__, __LINE__ end end diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb index 9c4412c28c..e14e225596 100644 --- a/activesupport/lib/active_support/dependencies.rb +++ b/activesupport/lib/active_support/dependencies.rb @@ -66,7 +66,7 @@ module ActiveSupport #:nodoc: end def self.locked(*methods) - methods.each { |m| class_eval "def #{m}(*) lock { super } end" } + methods.each { |m| class_eval "def #{m}(*) lock { super } end", __FILE__, __LINE__ } end def get(key) diff --git a/activesupport/lib/active_support/testing/declarative.rb b/activesupport/lib/active_support/testing/declarative.rb index a7df473644..70a6c2ca60 100644 --- a/activesupport/lib/active_support/testing/declarative.rb +++ b/activesupport/lib/active_support/testing/declarative.rb @@ -7,7 +7,7 @@ module ActiveSupport unless method_defined?(:describe) def self.describe(text) - class_eval <<-RUBY_EVAL + class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1 def self.name "#{text}" end diff --git a/activesupport/test/dependencies_test.rb b/activesupport/test/dependencies_test.rb index 2cbf9e5042..75ff88505d 100644 --- a/activesupport/test/dependencies_test.rb +++ b/activesupport/test/dependencies_test.rb @@ -371,7 +371,7 @@ class DependenciesTest < Test::Unit::TestCase end def test_custom_const_missing_should_work - Object.module_eval <<-end_eval + Object.module_eval <<-end_eval, __FILE__, __LINE__ + 1 module ModuleWithCustomConstMissing def self.const_missing(name) const_set name, name.to_s.hash diff --git a/activesupport/test/inflector_test.rb b/activesupport/test/inflector_test.rb index 76bdc0e973..2990177bed 100644 --- a/activesupport/test/inflector_test.rb +++ b/activesupport/test/inflector_test.rb @@ -209,14 +209,14 @@ class InflectorTest < Test::Unit::TestCase end %w{plurals singulars uncountables humans}.each do |inflection_type| - class_eval " + class_eval <<-RUBY, __FILE__, __LINE__ + 1 def test_clear_#{inflection_type} cached_values = ActiveSupport::Inflector.inflections.#{inflection_type} ActiveSupport::Inflector.inflections.clear :#{inflection_type} assert ActiveSupport::Inflector.inflections.#{inflection_type}.empty?, \"#{inflection_type} inflections should be empty after clear :#{inflection_type}\" ActiveSupport::Inflector.inflections.instance_variable_set :@#{inflection_type}, cached_values end - " + RUBY end def test_clear_all diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index ee44acc2fa..cd4a3dce4e 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -17,7 +17,7 @@ module Rails private %w(template copy_file directory empty_directory inside empty_directory_with_gitkeep create_file chmod shebang).each do |method| - class_eval <<-RUBY + class_eval <<-RUBY, __FILE__, __LINE__ + 1 def #{method}(*args, &block) @generator.send(:#{method}, *args, &block) end |