aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/inflector/methods.rb
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2011-09-08 20:49:08 +0200
committerJosé Valim <jose.valim@gmail.com>2011-09-08 20:54:30 +0200
commit6b010c2690de9ffce4878a9471c8adb33d4a21a1 (patch)
treeb6f6053d93b64672334701a6ff3d5aae5d41dfa8 /activesupport/lib/active_support/inflector/methods.rb
parent0d254915819a9e5711895e410e1597177216c903 (diff)
downloadrails-6b010c2690de9ffce4878a9471c8adb33d4a21a1.tar.gz
rails-6b010c2690de9ffce4878a9471c8adb33d4a21a1.tar.bz2
rails-6b010c2690de9ffce4878a9471c8adb33d4a21a1.zip
Revert removing gsub and sub from safe buffer.
Diffstat (limited to 'activesupport/lib/active_support/inflector/methods.rb')
-rw-r--r--activesupport/lib/active_support/inflector/methods.rb32
1 files changed, 8 insertions, 24 deletions
diff --git a/activesupport/lib/active_support/inflector/methods.rb b/activesupport/lib/active_support/inflector/methods.rb
index e1aba44813..423b5abd20 100644
--- a/activesupport/lib/active_support/inflector/methods.rb
+++ b/activesupport/lib/active_support/inflector/methods.rb
@@ -21,8 +21,7 @@ module ActiveSupport
# "words".pluralize # => "words"
# "CamelOctopus".pluralize # => "CamelOctopi"
def pluralize(word)
- word = deprecate_symbol(word)
- result = word.to_str.dup
+ result = word.to_s.dup
if word.empty? || inflections.uncountables.include?(result.downcase)
result
@@ -41,8 +40,7 @@ module ActiveSupport
# "word".singularize # => "word"
# "CamelOctopi".singularize # => "CamelOctopus"
def singularize(word)
- word = deprecate_symbol(word)
- result = word.to_str.dup
+ result = word.to_s.dup
if inflections.uncountables.any? { |inflection| result =~ /\b(#{inflection})\Z/i }
result
@@ -68,8 +66,7 @@ module ActiveSupport
#
# "SSLError".underscore.camelize # => "SslError"
def camelize(term, uppercase_first_letter = true)
- term = deprecate_symbol(term)
- string = term.to_str
+ string = term.to_s
if uppercase_first_letter
string = string.sub(/^[a-z\d]*/) { inflections.acronyms[$&] || $&.capitalize }
else
@@ -91,8 +88,7 @@ module ActiveSupport
#
# "SSLError".underscore.camelize # => "SslError"
def underscore(camel_cased_word)
- camel_cased_word = deprecate_symbol(camel_cased_word)
- word = camel_cased_word.to_str.dup
+ word = camel_cased_word.to_s.dup
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')
@@ -109,8 +105,7 @@ module ActiveSupport
# "employee_salary" # => "Employee salary"
# "author_id" # => "Author"
def humanize(lower_case_and_underscored_word)
- lower_case_and_underscored_word = deprecate_symbol(lower_case_and_underscored_word)
- result = lower_case_and_underscored_word.to_str.dup
+ result = lower_case_and_underscored_word.to_s.dup
inflections.humans.each { |(rule, replacement)| break if result.gsub!(rule, replacement) }
result.gsub!(/_id$/, "")
result.gsub(/(_)?([a-z\d]*)/i) { "#{$1 && ' '}#{inflections.acronyms[$2] || $2.downcase}" }.gsub(/^\w/) { $&.upcase }
@@ -153,9 +148,8 @@ module ActiveSupport
# Singular names are not handled correctly:
# "business".classify # => "Busines"
def classify(table_name)
- table_name = deprecate_symbol(table_name)
# strip out any leading schema name
- camelize(singularize(table_name.to_str.sub(/.*\./, '')))
+ camelize(singularize(table_name.to_s.sub(/.*\./, '')))
end
# Replaces underscores with dashes in the string.
@@ -163,8 +157,7 @@ module ActiveSupport
# Example:
# "puni_puni" # => "puni-puni"
def dasherize(underscored_word)
- underscored_word = deprecate_symbol(underscored_word)
- underscored_word.to_str.gsub(/_/, '-')
+ underscored_word.gsub(/_/, '-')
end
# Removes the module part from the expression in the string.
@@ -173,8 +166,7 @@ module ActiveSupport
# "ActiveRecord::CoreExtensions::String::Inflections".demodulize # => "Inflections"
# "Inflections".demodulize # => "Inflections"
def demodulize(class_name_in_module)
- class_name_in_module = deprecate_symbol(class_name_in_module)
- class_name_in_module.to_str.gsub(/^.*::/, '')
+ class_name_in_module.to_s.gsub(/^.*::/, '')
end
# Creates a foreign key name from a class name.
@@ -254,13 +246,5 @@ module ActiveSupport
end
end
end
-
- def deprecate_symbol(symbol)
- if symbol.is_a?(Symbol)
- symbol = symbol.to_s
- ActiveSupport::Deprecation.warn("Using symbols in inflections is deprecated. Please use to_s to have a string.")
- end
- symbol
- end
end
end