aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/lib/action_view/helpers/asset_url_helper.rb
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2016-07-25 00:31:35 +0200
committerXavier Noria <fxn@hashref.com>2016-07-25 00:31:35 +0200
commit7ebef567ce30d848dd8f9374fd70699fd91acb29 (patch)
tree9452737beec405626f309348b6d3c7fe4838ed91 /actionview/lib/action_view/helpers/asset_url_helper.rb
parent11b463d8cbacfe2cc1662f9e314440de71806ca9 (diff)
downloadrails-7ebef567ce30d848dd8f9374fd70699fd91acb29.tar.gz
rails-7ebef567ce30d848dd8f9374fd70699fd91acb29.tar.bz2
rails-7ebef567ce30d848dd8f9374fd70699fd91acb29.zip
systematic revision of =~ usage in AV
Where appropriate, prefer the more concise Regexp#match?, String#include?, String#start_with?, or String#end_with?
Diffstat (limited to 'actionview/lib/action_view/helpers/asset_url_helper.rb')
-rw-r--r--actionview/lib/action_view/helpers/asset_url_helper.rb23
1 files changed, 13 insertions, 10 deletions
diff --git a/actionview/lib/action_view/helpers/asset_url_helper.rb b/actionview/lib/action_view/helpers/asset_url_helper.rb
index 717b326740..8af01617fa 100644
--- a/actionview/lib/action_view/helpers/asset_url_helper.rb
+++ b/actionview/lib/action_view/helpers/asset_url_helper.rb
@@ -1,4 +1,5 @@
require 'zlib'
+require 'active_support/core_ext/regexp'
module ActionView
# = Action View Asset URL Helpers
@@ -131,8 +132,8 @@ module ActionView
raise ArgumentError, "nil is not a valid asset source" if source.nil?
source = source.to_s
- return "" unless source.present?
- return source if source =~ URI_REGEXP
+ return '' if source.blank?
+ return source if URI_REGEXP.match?(source)
tail, source = source[/([\?#].+)$/], source.sub(/([\?#].+)$/, ''.freeze)
@@ -213,19 +214,21 @@ module ActionView
host = options[:host]
host ||= config.asset_host if defined? config.asset_host
- if host.respond_to?(:call)
- arity = host.respond_to?(:arity) ? host.arity : host.method(:call).arity
- args = [source]
- args << request if request && (arity > 1 || arity < 0)
- host = host.call(*args)
- elsif host =~ /%d/
- host = host % (Zlib.crc32(source) % 4)
+ if host
+ if host.respond_to?(:call)
+ arity = host.respond_to?(:arity) ? host.arity : host.method(:call).arity
+ args = [source]
+ args << request if request && (arity > 1 || arity < 0)
+ host = host.call(*args)
+ elsif host.include?('%d')
+ host = host % (Zlib.crc32(source) % 4)
+ end
end
host ||= request.base_url if request && options[:protocol] == :request
return unless host
- if host =~ URI_REGEXP
+ if URI_REGEXP.match?(host)
host
else
protocol = options[:protocol] || config.default_asset_host_protocol || (request ? :request : :relative)