未验证 提交 46a22cea 编写于 作者: R Ryuta Kamizono 提交者: GitHub

Merge pull request #39162 from kamipo/dogfooding_symbol_starts_ends_with

Dogfooding "active_support/core_ext/symbol/starts_ends_with"
# frozen_string_literal: true
require "active_support/core_ext/symbol/starts_ends_with"
module AbstractController
module Translation
# Delegates to <tt>I18n.translate</tt>. Also aliased as <tt>t</tt>.
......@@ -11,7 +13,7 @@ module Translation
# to translate many keys within the same controller / action and gives you a
# simple framework for scoping them consistently.
def translate(key, **options)
if key.to_s.start_with?(".")
if key.start_with?(".")
path = controller_path.tr("/", ".")
defaults = [:"#{path}#{key}"]
defaults << options[:default] if options[:default]
......
# frozen_string_literal: true
require "singleton"
require "active_support/core_ext/symbol/starts_ends_with"
module Mime
class Mimes
......@@ -305,7 +306,7 @@ def to_ary; end
def to_a; end
def method_missing(method, *args)
if method.to_s.end_with? "?"
if method.end_with?("?")
method[0..-2].downcase.to_sym == to_sym
else
super
......@@ -313,7 +314,7 @@ def method_missing(method, *args)
end
def respond_to_missing?(method, include_private = false)
(method.to_s.end_with? "?") || super
method.end_with?("?") || super
end
end
......@@ -348,11 +349,11 @@ def ref; end
private
def respond_to_missing?(method, _)
method.to_s.end_with? "?"
method.end_with?("?")
end
def method_missing(method, *args)
false if method.to_s.end_with? "?"
false if method.end_with?("?")
end
end
end
......
......@@ -4,6 +4,7 @@
require "active_support/core_ext/enumerable"
require "active_support/core_ext/array/extract_options"
require "active_support/core_ext/regexp"
require "active_support/core_ext/symbol/starts_ends_with"
require "action_dispatch/routing/redirection"
require "action_dispatch/routing/endpoint"
......@@ -355,7 +356,7 @@ def split_to(to)
def add_controller_module(controller, modyoule)
if modyoule && !controller.is_a?(Regexp)
if controller.to_s.start_with?("/")
if controller&.start_with?("/")
controller[1..-1]
else
[modyoule, controller].compact.join("/")
......
......@@ -14,7 +14,7 @@ module Assertions
include Rails::Dom::Testing::Assertions
def html_document
@html_document ||= if @response.media_type.to_s.end_with?("xml")
@html_document ||= if @response.media_type&.end_with?("xml")
Nokogiri::XML::Document.parse(@response.body)
else
Nokogiri::HTML::Document.parse(@response.body)
......
......@@ -2162,6 +2162,7 @@ def fields_for(record_name, record_object = nil, fields_options = {}, &block)
case record_name
when String, Symbol
record_name = record_name.to_s
if nested_attributes_association?(record_name)
return fields_for_with_nested_attributes(record_name, record_object, fields_options, block)
end
......@@ -2180,8 +2181,8 @@ def fields_for(record_name, record_object = nil, fields_options = {}, &block)
record_name = if index
"#{object_name}[#{index}][#{record_name}]"
elsif record_name.to_s.end_with?("[]")
record_name = record_name.to_s.sub(/(.*)\[\]$/, "[\\1][#{record_object.id}]")
elsif record_name.end_with?("[]")
record_name = record_name.sub(/(.*)\[\]$/, "[\\1][#{record_object.id}]")
"#{object_name}#{record_name}"
else
"#{object_name}[#{record_name}]"
......
......@@ -4,6 +4,7 @@
require "action_view/helpers/tag_helper"
require "active_support/core_ext/string/output_safety"
require "active_support/core_ext/module/attribute_accessors"
require "active_support/core_ext/symbol/starts_ends_with"
module ActionView
# = Action View Form Tag Helpers
......@@ -134,7 +135,7 @@ def form_tag(url_for_options = {}, options = {}, &block)
# # <option selected="selected">MasterCard</option></select>
def select_tag(name, option_tags = nil, options = {})
option_tags ||= ""
html_name = (options[:multiple] == true && !name.to_s.end_with?("[]")) ? "#{name}[]" : name
html_name = (options[:multiple] == true && !name.end_with?("[]")) ? "#{name}[]" : name
if options.include?(:include_blank)
include_blank = options[:include_blank]
......
......@@ -3,6 +3,7 @@
require "cases/helper"
require "models/developer"
require "models/computer"
require "active_support/core_ext/symbol/starts_ends_with"
class CallbackDeveloper < ActiveRecord::Base
self.table_name = "developers"
......@@ -29,7 +30,7 @@ def callback_object(callback_method)
end
ActiveRecord::Callbacks::CALLBACKS.each do |callback_method|
next if callback_method.to_s.start_with?("around_")
next if callback_method.start_with?("around_")
define_callback_method(callback_method)
send(callback_method, callback_proc(callback_method))
send(callback_method, callback_object(callback_method))
......
......@@ -3,6 +3,7 @@
require "cases/helper"
require "models/post"
require "models/comment"
require "active_support/core_ext/symbol/starts_ends_with"
module ActiveRecord
module DelegationTests
......@@ -50,7 +51,7 @@ class QueryingMethodsDelegationTest < ActiveRecord::TestCase
ActiveRecord::FinderMethods.public_instance_methods(false) - [:raise_record_not_found_exception!] +
ActiveRecord::SpawnMethods.public_instance_methods(false) - [:spawn, :merge!] +
ActiveRecord::QueryMethods.public_instance_methods(false).reject { |method|
method.to_s.end_with?("=", "!", "value", "values", "clause")
method.end_with?("=", "!", "value", "values", "clause")
} - [:reverse_order, :arel, :extensions, :construct_join_dependency] + [
:any?, :many?, :none?, :one?,
:first_or_create, :first_or_create!, :first_or_initialize,
......
......@@ -148,7 +148,7 @@ def directories_to_watch
normalized_gem_paths = Gem.path.map { |path| File.join path, "" }
dtw = dtw.reject do |path|
normalized_gem_paths.any? { |gem_path| path.to_s.start_with?(gem_path) }
normalized_gem_paths.any? { |gem_path| path.to_path.start_with?(gem_path) }
end
@ph.filter_out_descendants(dtw)
......
# frozen_string_literal: true
require "active_support/core_ext/hash/deep_merge"
require "active_support/core_ext/symbol/starts_ends_with"
module ActiveSupport
class OptionMerger #:nodoc:
instance_methods.each do |method|
undef_method(method) unless method.to_s.start_with?("__", "instance_eval", "class", "object_id")
undef_method(method) unless method.start_with?("__", "instance_eval", "class", "object_id")
end
def initialize(context, options)
......
......@@ -5,6 +5,7 @@
require "rails"
require "active_support/deprecation"
require "active_support/core_ext/string/filters"
require "active_support/core_ext/symbol/starts_ends_with"
require "rails/dev_caching"
require "rails/command/environment_argument"
......@@ -178,7 +179,7 @@ def user_supplied_options
# ["-p3001", "-C", "--binding", "127.0.0.1"] # => {"-p"=>true, "-C"=>true, "--binding"=>true}
user_flag = {}
@original_options.each do |command|
if command.to_s.start_with?("--")
if command.start_with?("--")
option = command.split("=")[0]
user_flag[option] = true
elsif command =~ /\A(-.)/
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册