mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #2852 from milandobrota/remove_unneeded_explicit_nil_checks
if ... nil? is more expensive than unless
This commit is contained in:
commit
e865d12543
7 changed files with 11 additions and 11 deletions
|
@ -88,7 +88,7 @@ module ActionController #:nodoc:
|
||||||
end
|
end
|
||||||
|
|
||||||
def method_missing(method, *arguments, &block)
|
def method_missing(method, *arguments, &block)
|
||||||
return if @controller.nil?
|
return unless @controller
|
||||||
@controller.__send__(method, *arguments, &block)
|
@controller.__send__(method, *arguments, &block)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -57,7 +57,7 @@ module ActionController
|
||||||
# When using <tt>redirect_to :back</tt>, if there is no referrer, RedirectBackError will be raised. You may specify some fallback
|
# When using <tt>redirect_to :back</tt>, if there is no referrer, RedirectBackError will be raised. You may specify some fallback
|
||||||
# behavior for this case by rescuing RedirectBackError.
|
# behavior for this case by rescuing RedirectBackError.
|
||||||
def redirect_to(options = {}, response_status = {}) #:doc:
|
def redirect_to(options = {}, response_status = {}) #:doc:
|
||||||
raise ActionControllerError.new("Cannot redirect to nil!") if options.nil?
|
raise ActionControllerError.new("Cannot redirect to nil!") unless options
|
||||||
raise AbstractController::DoubleRenderError if response_body
|
raise AbstractController::DoubleRenderError if response_body
|
||||||
|
|
||||||
self.status = _extract_redirect_to_status(options, response_status)
|
self.status = _extract_redirect_to_status(options, response_status)
|
||||||
|
|
|
@ -79,10 +79,10 @@ module ActionController
|
||||||
"expecting <?> but rendering with <?>",
|
"expecting <?> but rendering with <?>",
|
||||||
options, rendered.keys.join(', '))
|
options, rendered.keys.join(', '))
|
||||||
assert_block(msg) do
|
assert_block(msg) do
|
||||||
if options.nil?
|
if options
|
||||||
@templates.blank?
|
|
||||||
else
|
|
||||||
rendered.any? { |t,num| t.match(options) }
|
rendered.any? { |t,num| t.match(options) }
|
||||||
|
else
|
||||||
|
@templates.blank?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
when Hash
|
when Hash
|
||||||
|
|
|
@ -1436,7 +1436,7 @@ module ActionDispatch
|
||||||
name_prefix = @scope[:as]
|
name_prefix = @scope[:as]
|
||||||
|
|
||||||
if parent_resource
|
if parent_resource
|
||||||
return nil if as.nil? && action.nil?
|
return nil unless as || action
|
||||||
|
|
||||||
collection_name = parent_resource.collection_name
|
collection_name = parent_resource.collection_name
|
||||||
member_name = parent_resource.member_name
|
member_name = parent_resource.member_name
|
||||||
|
|
|
@ -69,7 +69,7 @@ module ActionView
|
||||||
host = "#{compute_protocol(protocol)}#{host}"
|
host = "#{compute_protocol(protocol)}#{host}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
host.nil? ? source : "#{host}#{source}"
|
host ? "#{host}#{source}" : source
|
||||||
end
|
end
|
||||||
|
|
||||||
def compute_protocol(protocol)
|
def compute_protocol(protocol)
|
||||||
|
|
|
@ -656,7 +656,7 @@ module ActionView
|
||||||
if token == false || !protect_against_forgery?
|
if token == false || !protect_against_forgery?
|
||||||
''
|
''
|
||||||
else
|
else
|
||||||
token = form_authenticity_token if token.nil?
|
token ||= form_authenticity_token
|
||||||
tag(:input, :type => "hidden", :name => request_forgery_protection_token.to_s, :value => token)
|
tag(:input, :type => "hidden", :name => request_forgery_protection_token.to_s, :value => token)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -596,9 +596,7 @@ module ActionView
|
||||||
|
|
||||||
private
|
private
|
||||||
def convert_options_to_data_attributes(options, html_options)
|
def convert_options_to_data_attributes(options, html_options)
|
||||||
if html_options.nil?
|
if html_options
|
||||||
link_to_remote_options?(options) ? {'data-remote' => 'true'} : {}
|
|
||||||
else
|
|
||||||
html_options = html_options.stringify_keys
|
html_options = html_options.stringify_keys
|
||||||
html_options['data-remote'] = 'true' if link_to_remote_options?(options) || link_to_remote_options?(html_options)
|
html_options['data-remote'] = 'true' if link_to_remote_options?(options) || link_to_remote_options?(html_options)
|
||||||
|
|
||||||
|
@ -611,6 +609,8 @@ module ActionView
|
||||||
add_method_to_attributes!(html_options, method) if method
|
add_method_to_attributes!(html_options, method) if method
|
||||||
|
|
||||||
html_options
|
html_options
|
||||||
|
else
|
||||||
|
link_to_remote_options?(options) ? {'data-remote' => 'true'} : {}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue