diff options
author | Damien Mathieu <42@dmathieu.com> | 2011-09-08 10:21:50 +0200 |
---|---|---|
committer | Damien Mathieu <42@dmathieu.com> | 2011-09-08 10:22:21 +0200 |
commit | 3718ccd2a61c2c189913bcfd487912f592fa0660 (patch) | |
tree | 81a0710cb8f3ddd4a2b77d894b021f777f429a8e /activesupport/lib/active_support/inflector/methods.rb | |
parent | e9f48cdcf482c5a878267a18fb9ed352f5f30dea (diff) | |
download | rails-3718ccd2a61c2c189913bcfd487912f592fa0660.tar.gz rails-3718ccd2a61c2c189913bcfd487912f592fa0660.tar.bz2 rails-3718ccd2a61c2c189913bcfd487912f592fa0660.zip |
remove support of symbols on classify and camelize
Diffstat (limited to 'activesupport/lib/active_support/inflector/methods.rb')
-rw-r--r-- | activesupport/lib/active_support/inflector/methods.rb | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/inflector/methods.rb b/activesupport/lib/active_support/inflector/methods.rb index e006eddc0c..e1aba44813 100644 --- a/activesupport/lib/active_support/inflector/methods.rb +++ b/activesupport/lib/active_support/inflector/methods.rb @@ -21,6 +21,7 @@ module ActiveSupport # "words".pluralize # => "words" # "CamelOctopus".pluralize # => "CamelOctopi" def pluralize(word) + word = deprecate_symbol(word) result = word.to_str.dup if word.empty? || inflections.uncountables.include?(result.downcase) @@ -40,6 +41,7 @@ module ActiveSupport # "word".singularize # => "word" # "CamelOctopi".singularize # => "CamelOctopus" def singularize(word) + word = deprecate_symbol(word) result = word.to_str.dup if inflections.uncountables.any? { |inflection| result =~ /\b(#{inflection})\Z/i } @@ -66,6 +68,7 @@ module ActiveSupport # # "SSLError".underscore.camelize # => "SslError" def camelize(term, uppercase_first_letter = true) + term = deprecate_symbol(term) string = term.to_str if uppercase_first_letter string = string.sub(/^[a-z\d]*/) { inflections.acronyms[$&] || $&.capitalize } @@ -88,6 +91,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.gsub!(/::/, '/') word.gsub!(/(?:([A-Za-z\d])|^)(#{inflections.acronym_regex})(?=\b|[^a-z])/) { "#{$1}#{$1 && '_'}#{$2.downcase}" } @@ -105,6 +109,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 inflections.humans.each { |(rule, replacement)| break if result.gsub!(rule, replacement) } result.gsub!(/_id$/, "") @@ -148,6 +153,7 @@ 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(/.*\./, ''))) end @@ -157,6 +163,7 @@ module ActiveSupport # Example: # "puni_puni" # => "puni-puni" def dasherize(underscored_word) + underscored_word = deprecate_symbol(underscored_word) underscored_word.to_str.gsub(/_/, '-') end @@ -166,6 +173,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(/^.*::/, '') end @@ -246,5 +254,13 @@ 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 |