From 1f62443319c1b95c6e747a5de5e7e1041c64cbcb Mon Sep 17 00:00:00 2001 From: Andrew White Date: Wed, 2 Nov 2016 16:00:37 +0000 Subject: Fix inconsistencies in path with missing helpers Ruby 2.0 and later demonstrate some inconsistencies when a helper file is not found with the path method on LoadError. By creating a subclass of LoadError we can cater for the inconsistencies. --- actionpack/lib/abstract_controller/helpers.rb | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/abstract_controller/helpers.rb b/actionpack/lib/abstract_controller/helpers.rb index 77cc4c07d9..7a9055a679 100644 --- a/actionpack/lib/abstract_controller/helpers.rb +++ b/actionpack/lib/abstract_controller/helpers.rb @@ -12,6 +12,15 @@ module AbstractController self._helper_methods = Array.new end + class MissingHelperError < LoadError + def initialize(error, path) + @error = error + @path = "helpers/#{path}.rb" + set_backtrace error.backtrace + super("Missing helper file helpers/%s.rb" % path) + end + end + module ClassMethods # When a class is inherited, wrap its helper module in a new module. # This ensures that the parent class's module can be changed @@ -132,7 +141,11 @@ module AbstractController case arg when String, Symbol file_name = "#{arg.to_s.underscore}_helper" - require_dependency(file_name, "Missing helper file helpers/%s.rb") + begin + require_dependency(file_name) + rescue LoadError => e + raise MissingHelperError.new(e, file_name) + end file_name.camelize.constantize when Module arg -- cgit v1.2.3 From 2b1ec283d41898cbe1e2f60f72ed40ebc0d2672a Mon Sep 17 00:00:00 2001 From: Andrew White Date: Wed, 2 Nov 2016 16:07:24 +0000 Subject: Fix File.exists? deprecation warnings in Action Pack --- .../lib/action_view/helpers/asset_tag_helpers/asset_include_tag.rb | 2 +- actionpack/lib/sprockets/helpers/rails_helper.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/asset_tag_helpers/asset_include_tag.rb b/actionpack/lib/action_view/helpers/asset_tag_helpers/asset_include_tag.rb index 05d5f1870a..edfc374b3b 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helpers/asset_include_tag.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helpers/asset_include_tag.rb @@ -47,7 +47,7 @@ module ActionView if concat || (config.perform_caching && cache) joined_name = (cache == true ? "all" : cache) + ".#{extension}" joined_path = File.join((joined_name[/^#{File::SEPARATOR}/] ? config.assets_dir : custom_dir), joined_name) - unless config.perform_caching && File.exists?(joined_path) + unless config.perform_caching && File.exist?(joined_path) write_asset_file_contents(joined_path, compute_paths(sources, recursive)) end asset_tag(joined_name, options) diff --git a/actionpack/lib/sprockets/helpers/rails_helper.rb b/actionpack/lib/sprockets/helpers/rails_helper.rb index 243c2e5e50..6712aefb2d 100644 --- a/actionpack/lib/sprockets/helpers/rails_helper.rb +++ b/actionpack/lib/sprockets/helpers/rails_helper.rb @@ -163,7 +163,7 @@ module Sprockets source elsif source_ext.blank? "#{source}.#{ext}" - elsif File.exists?(source) || exact_match_present?(source) + elsif File.exist?(source) || exact_match_present?(source) source else "#{source}.#{ext}" -- cgit v1.2.3 From b12b4be0b8070a0e16f7ab0125c4f0aec1766bcc Mon Sep 17 00:00:00 2001 From: Andrew White Date: Wed, 2 Nov 2016 16:13:26 +0000 Subject: Double assign locals to avoid unused variables warning --- actionpack/lib/action_view/template.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/template.rb b/actionpack/lib/action_view/template.rb index e67e52cc76..069ac4e761 100644 --- a/actionpack/lib/action_view/template.rb +++ b/actionpack/lib/action_view/template.rb @@ -323,7 +323,8 @@ module ActionView end def locals_code #:nodoc: - @locals.map { |key| "#{key} = local_assigns[:#{key}];" }.join + # Double assign to suppress the dreaded 'assigned but unused variable' warning + @locals.map { |key| "#{key} = #{key} = local_assigns[:#{key}];" }.join end def method_name #:nodoc: -- cgit v1.2.3