提交 a9398a7d 编写于 作者: S Santiago Pastorino

Merge pull request #5716 from jurriaan/tr-gsub-cleanup

Updated/changed unneeded tr/gsubs
......@@ -696,7 +696,7 @@ def set_content_type(m, user_content_type, class_default)
# If it does not find a translation for the +subject+ under the specified scope it will default to a
# humanized version of the <tt>action_name</tt>.
def default_i18n_subject #:nodoc:
mailer_scope = self.class.mailer_name.gsub('/', '.')
mailer_scope = self.class.mailer_name.tr('/', '.')
I18n.t(:subject, :scope => [mailer_scope, action_name], :default => action_name.humanize)
end
......
......@@ -6,7 +6,7 @@ class <%= class_name %> < ActionMailer::Base
# Subject can be set in your I18n file at config/locales/en.yml
# with the following lookup:
#
# en.<%= file_path.gsub("/",".") %>.<%= action %>.subject
# en.<%= file_path.tr("/",".") %>.<%= action %>.subject
#
def <%= action %>
@greeting = "Hi"
......
......@@ -132,7 +132,7 @@ def send_file_headers!(options)
else
if !type_provided && options[:filename]
# If type wasn't provided, try guessing from file extension.
content_type = Mime::Type.lookup_by_extension(File.extname(options[:filename]).downcase.tr('.','')) || content_type
content_type = Mime::Type.lookup_by_extension(File.extname(options[:filename]).downcase.delete('.')) || content_type
end
self.content_type = content_type
end
......
......@@ -229,7 +229,7 @@ def decode_credentials_header(request)
def decode_credentials(header)
Hash[header.to_s.gsub(/^Digest\s+/,'').split(',').map do |pair|
key, value = pair.split('=', 2)
[key.strip.to_sym, value.to_s.gsub(/^"|"$/,'').gsub(/'/, '')]
[key.strip.to_sym, value.to_s.gsub(/^"|"$/,'').delete('\'')]
end]
end
......
......@@ -93,7 +93,7 @@ def _compute_redirect_to_location(options)
_compute_redirect_to_location options.call
else
url_for(options)
end.gsub(/[\0\r\n]/, '')
end.delete("\0\r\n")
end
end
end
......@@ -244,7 +244,7 @@ def self.normalize_path(path)
end
def self.normalize_name(name)
normalize_path(name)[1..-1].gsub("/", "_")
normalize_path(name)[1..-1].tr("/", "_")
end
module Base
......@@ -441,7 +441,7 @@ def app_name(app)
app.railtie_name
else
class_name = app.class.is_a?(Class) ? app.name : app.class.name
ActiveSupport::Inflector.underscore(class_name).gsub("/", "_")
ActiveSupport::Inflector.underscore(class_name).tr("/", "_")
end
end
......
......@@ -81,7 +81,7 @@ def normalize_argument_to_redirection(fragment)
refer
else
@controller.url_for(fragment)
end.gsub(/[\0\r\n]/, '')
end.delete("\0\r\n")
end
end
end
......
......@@ -137,12 +137,12 @@ def number_to_currency(number, options = {})
begin
value = number_with_precision(number, options.merge(:raise => true))
format.gsub(/%n/, value).gsub(/%u/, unit).html_safe
format.gsub('%n', value).gsub('%u', unit).html_safe
rescue InvalidNumberError => e
if options[:raise]
raise
else
formatted_number = format.gsub(/%n/, e.number).gsub(/%u/, unit)
formatted_number = format.gsub('%n', e.number).gsub('%u', unit)
e.number.to_s.html_safe? ? formatted_number.html_safe : formatted_number
end
end
......
......@@ -286,7 +286,7 @@ def full_messages
# "Name is invalid"
def full_message(attribute, message)
return message if attribute == :base
attr_name = attribute.to_s.gsub('.', '_').humanize
attr_name = attribute.to_s.tr('.', '_').humanize
attr_name = @base.class.human_attribute_name(attribute, :default => attr_name)
I18n.t(:"errors.format", {
:default => "%{attribute} %{message}",
......
......@@ -16,7 +16,7 @@ def native_database_types
# Truncates a table alias according to the limits of the current adapter.
def table_alias_for(table_name)
table_name[0...table_alias_length].gsub(/\./, '_')
table_name[0...table_alias_length].tr('.', '_')
end
# Checks to see if the table +table_name+ exists on the database.
......
......@@ -339,9 +339,9 @@ def columns(table_name) #:nodoc:
when /^null$/i
field["dflt_value"] = nil
when /^'(.*)'$/
field["dflt_value"] = $1.gsub(/''/, "'")
field["dflt_value"] = $1.gsub("''", "'")
when /^"(.*)"$/
field["dflt_value"] = $1.gsub(/""/, '"')
field["dflt_value"] = $1.gsub('""', '"')
end
SQLiteColumn.new(field['name'], field['dflt_value'], field['type'], field['notnull'].to_i == 0)
......
......@@ -77,7 +77,7 @@ def camelize(term, uppercase_first_letter = true)
# "SSLError".underscore.camelize # => "SslError"
def underscore(camel_cased_word)
word = camel_cased_word.to_s.dup
word.gsub!(/::/, '/')
word.gsub!('::', '/')
word.gsub!(/(?:([A-Za-z\d])|^)(#{inflections.acronym_regex})(?=\b|[^a-z])/) { "#{$1}#{$1 && '_'}#{$2.downcase}" }
word.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2')
word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
......
......@@ -76,7 +76,7 @@ def show_results(error_list)
error_summary += "\n #{name}"
error_detail += "\n\n #{name} has #{errors.size} validation error(s):\n"
errors.each do |error|
error_detail += "\n "+error.to_s.gsub("\n", "")
error_detail += "\n "+error.to_s.delete("\n")
end
end
......
......@@ -99,7 +99,7 @@ def plural_name
end
def i18n_scope
@i18n_scope ||= file_path.gsub('/', '.')
@i18n_scope ||= file_path.tr('/', '.')
end
def table_name
......
......@@ -50,7 +50,7 @@ def controller_class_name
end
def controller_i18n_scope
@controller_i18n_scope ||= controller_file_path.gsub('/', '.')
@controller_i18n_scope ||= controller_file_path.tr('/', '.')
end
# Loads the ORM::Generators::ActiveModel class. This class is responsible
......
......@@ -162,7 +162,7 @@ def railtie_name(name = nil)
protected
def generate_railtie_name(class_or_module)
ActiveSupport::Inflector.underscore(class_or_module).gsub("/", "_")
ActiveSupport::Inflector.underscore(class_or_module).tr("/", "_")
end
end
......
......@@ -43,7 +43,7 @@ def test_framework_version
def test_frameworks_exist
Rails::Info.frameworks.each do |framework|
dir = File.dirname(__FILE__) + "/../../" + framework.gsub('_', '')
dir = File.dirname(__FILE__) + "/../../" + framework.delete('_')
assert File.directory?(dir), "#{framework.classify} does not exist"
end
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册