From af2129b4c74732c88ffce76e5c55c805cb9431f6 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Thu, 1 Aug 2019 16:41:26 +0900 Subject: Use `try` only when we're unsure if the receiver would respond_to the method --- actionview/lib/action_view/helpers/sanitize_helper.rb | 3 +-- actionview/lib/action_view/helpers/tags/date_field.rb | 2 +- actionview/lib/action_view/helpers/tags/datetime_local_field.rb | 2 +- actionview/lib/action_view/helpers/tags/month_field.rb | 2 +- actionview/lib/action_view/helpers/tags/time_field.rb | 2 +- actionview/lib/action_view/helpers/tags/week_field.rb | 2 +- actionview/lib/action_view/renderer/streaming_template_renderer.rb | 2 +- actionview/lib/action_view/renderer/template_renderer.rb | 4 +--- 8 files changed, 8 insertions(+), 11 deletions(-) (limited to 'actionview') diff --git a/actionview/lib/action_view/helpers/sanitize_helper.rb b/actionview/lib/action_view/helpers/sanitize_helper.rb index f4fa133f55..fdce4fe688 100644 --- a/actionview/lib/action_view/helpers/sanitize_helper.rb +++ b/actionview/lib/action_view/helpers/sanitize_helper.rb @@ -1,6 +1,5 @@ # frozen_string_literal: true -require "active_support/core_ext/object/try" require "rails-html-sanitizer" module ActionView @@ -80,7 +79,7 @@ module ActionView # config.action_view.sanitized_allowed_tags = ['strong', 'em', 'a'] # config.action_view.sanitized_allowed_attributes = ['href', 'title'] def sanitize(html, options = {}) - self.class.white_list_sanitizer.sanitize(html, options).try(:html_safe) + self.class.white_list_sanitizer.sanitize(html, options)&.html_safe end # Sanitizes a block of CSS code. Used by +sanitize+ when it comes across a style attribute. diff --git a/actionview/lib/action_view/helpers/tags/date_field.rb b/actionview/lib/action_view/helpers/tags/date_field.rb index ceaabfa99c..9cdfc6991f 100644 --- a/actionview/lib/action_view/helpers/tags/date_field.rb +++ b/actionview/lib/action_view/helpers/tags/date_field.rb @@ -6,7 +6,7 @@ module ActionView class DateField < DatetimeField # :nodoc: private def format_date(value) - value.try(:strftime, "%Y-%m-%d") + value&.strftime("%Y-%m-%d") end end end diff --git a/actionview/lib/action_view/helpers/tags/datetime_local_field.rb b/actionview/lib/action_view/helpers/tags/datetime_local_field.rb index 8908bf9948..f0834ac6ce 100644 --- a/actionview/lib/action_view/helpers/tags/datetime_local_field.rb +++ b/actionview/lib/action_view/helpers/tags/datetime_local_field.rb @@ -12,7 +12,7 @@ module ActionView private def format_date(value) - value.try(:strftime, "%Y-%m-%dT%T") + value&.strftime("%Y-%m-%dT%T") end end end diff --git a/actionview/lib/action_view/helpers/tags/month_field.rb b/actionview/lib/action_view/helpers/tags/month_field.rb index 463866a181..b582bb4f79 100644 --- a/actionview/lib/action_view/helpers/tags/month_field.rb +++ b/actionview/lib/action_view/helpers/tags/month_field.rb @@ -6,7 +6,7 @@ module ActionView class MonthField < DatetimeField # :nodoc: private def format_date(value) - value.try(:strftime, "%Y-%m") + value&.strftime("%Y-%m") end end end diff --git a/actionview/lib/action_view/helpers/tags/time_field.rb b/actionview/lib/action_view/helpers/tags/time_field.rb index e74c578db9..e5e0b84891 100644 --- a/actionview/lib/action_view/helpers/tags/time_field.rb +++ b/actionview/lib/action_view/helpers/tags/time_field.rb @@ -6,7 +6,7 @@ module ActionView class TimeField < DatetimeField # :nodoc: private def format_date(value) - value.try(:strftime, "%T.%L") + value&.strftime("%T.%L") end end end diff --git a/actionview/lib/action_view/helpers/tags/week_field.rb b/actionview/lib/action_view/helpers/tags/week_field.rb index 5a403ed91d..7828a3149f 100644 --- a/actionview/lib/action_view/helpers/tags/week_field.rb +++ b/actionview/lib/action_view/helpers/tags/week_field.rb @@ -6,7 +6,7 @@ module ActionView class WeekField < DatetimeField # :nodoc: private def format_date(value) - value.try(:strftime, "%Y-W%V") + value&.strftime("%Y-W%V") end end end diff --git a/actionview/lib/action_view/renderer/streaming_template_renderer.rb b/actionview/lib/action_view/renderer/streaming_template_renderer.rb index 08a280c7ee..5942717b8d 100644 --- a/actionview/lib/action_view/renderer/streaming_template_renderer.rb +++ b/actionview/lib/action_view/renderer/streaming_template_renderer.rb @@ -62,7 +62,7 @@ module ActionView output = ActionView::StreamingBuffer.new(buffer) yielder = lambda { |*name| view._layout_for(*name) } - instrument(:template, identifier: template.identifier, layout: layout.try(:virtual_path)) do + instrument(:template, identifier: template.identifier, layout: (layout && layout.virtual_path)) do outer_config = I18n.config fiber = Fiber.new do I18n.config = outer_config diff --git a/actionview/lib/action_view/renderer/template_renderer.rb b/actionview/lib/action_view/renderer/template_renderer.rb index b2d7332572..da0b2dc0d2 100644 --- a/actionview/lib/action_view/renderer/template_renderer.rb +++ b/actionview/lib/action_view/renderer/template_renderer.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require "active_support/core_ext/object/try" - module ActionView class TemplateRenderer < AbstractRenderer #:nodoc: def render(context, options) @@ -54,7 +52,7 @@ module ActionView # supplied as well. def render_template(view, template, layout_name, locals) render_with_layout(view, template, layout_name, locals) do |layout| - instrument(:template, identifier: template.identifier, layout: layout.try(:virtual_path)) do + instrument(:template, identifier: template.identifier, layout: (layout && layout.virtual_path)) do template.render(view, locals) { |*name| view._layout_for(*name) } end end -- cgit v1.2.3