aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/inflector/methods.rb
Commit message (Collapse)AuthorAgeFilesLines
...
* Merge pull request #14146 from chewi/fix-underscore-acronyms-regexMatthew Draper2014-10-041-1/+1
|\ | | | | | | Fix underscore inflector handling of namespaced and adjacent acronyms
| * Fix underscore inflector handling of adjacent acronymsJames Le Cuirot2014-10-031-1/+1
|/ | | | | | | | | | | | | I suspect that positive lookbehind would have been used in the original implementation had it been available in supported Ruby versions at the time. Now that Rails requires Ruby 1.9.2 or above, this is no longer an issue. This fixes #14146 for acronyms such as APIRESTful. This technique also addresses namespaced acronyms that are not entirely uppercased. This was broken when the commit was originally written but has since been fixed in ccbb481. The latter does not deal with adjacent acronyms so this commit wins.
* Fix for inflector's incorrect camelCase replacement for acronymsMatthew Draper2014-09-061-1/+1
| | | | | | Fixes #8015, #9756. [Fred Wu & Matthew Draper]
* Merge pull request #16338 from robin850/rbx-safe-constantizeMatthew Draper2014-08-181-2/+2
|\ | | | | Avoid relying on error messages when rescuing
| * Avoid relying on error messages when rescuingRobin Dupret2014-08-081-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When we are rescuing from an error, it's a brittle approach to do checks with regular expressions on the raised message because it may change in in the future and error messages are different across implementations. The NameError API could be improved at the MRI level but for now we need to rely on its #name. A #== check will only pass for top level constants or only when the last constant of the path is missing so we need to rely on #include? instead. For instance: begin Namespace::Foo rescue NameError => e e.name # => :Namespace end However, if the name-space already exists, only the name of the first missing constant in the path is returned (e.g. for Math::PHI, the name would be :PHI). JRuby will return a fully qualified name (:"Math::PHI"). We need to keep the == check for 1.9 compatibility since const_get will raise a NameError with a name attribute set to the given string if it's one of "::" or "". See http://git.io/jnSN7g for further information.
* | Fix the #const_regexp's documentation [ci skip]Robin Dupret2014-08-081-3/+4
|/ | | | | | Originally introduced in f9086d63, the documentation of this method is wrong as #const_regexp returns a string to easy the interpolation inside regular expressions.
* several enhancements to humanize [closes #12288]Xavier Noria2014-05-061-9/+29
| | | | | | | | | | * Strips leading underscores. * Changes some unnecessary gsub!s to sub!s. * Replaces some anchors ^, $ with \A, \z. * Documents that human inflection rules are applied. * Documents that words are downcased except acronyms. * Adds an example with an acronym. * Rewords docs.
* Merge pull request #14840 from akshay-vishnoi/doc_changesArthur Nogueira Neves2014-04-231-2/+2
|\ | | | | Correct comment [ci skip]
| * Correct comment [ci skip]Akshay Vishnoi2014-04-231-2/+2
| |
* | Changed miss-leading comment [ci skip]Arun Agrawal2014-04-201-1/+1
| | | | | | | | | | | | | | | | | | | | | | After this 21dbe6f39b57f52967e92716dbd5e2b894e7a64c 2.1.1 :001 > 'business'.classify => "Business" 2.1.1 :004 > 'calculus'.classify => "Calculu" 2.1.1 :005 >
* | [ci-skip] correct the classify example's outputKuldeep Aggarwal2014-04-211-1/+1
|/
* [ci skip] builtin -> built-inAkshay Vishnoi2014-04-201-2/+2
|
* Add more test case for #demodulize, Improve documentationAkshay Vishnoi2014-04-111-0/+2
|
* speed up `underscore` in cases that don't need to do anythingAaron Patterson2014-02-261-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Benchmark: Benchmark.ips do |x| x.report("home") { "home".underscore } x.report("Home") { "Home".underscore } x.report("homeBase") { "homeBase".underscore } x.report("home::base") { "home::base".underscore } end Before: Calculating ------------------------------------- home 2598 i/100ms Home 2463 i/100ms homeBase 2300 i/100ms home::base 2086 i/100ms ------------------------------------------------- home 28522.3 (±14.7%) i/s - 140292 in 5.065102s Home 29165.8 (±14.9%) i/s - 140391 in 5.000475s homeBase 26218.5 (±7.1%) i/s - 131100 in 5.030485s home::base 27712.3 (±5.9%) i/s - 139762 in 5.064077s After: Calculating ------------------------------------- home 23163 i/100ms Home 2432 i/100ms homeBase 2160 i/100ms home::base 2265 i/100ms ------------------------------------------------- home 1501614.8 (±10.2%) i/s - 7412160 in 5.009540s Home 28754.0 (±8.5%) i/s - 143488 in 5.033886s homeBase 25331.1 (±5.6%) i/s - 127440 in 5.047940s home::base 27089.9 (±5.5%) i/s - 135900 in 5.033516s
* fix interplay of humanize and html_escapeSean Walbran2014-02-051-1/+1
|
* Replace with gsub! in ActiveSupport::Inflector.Elben Shira2013-12-101-1/+2
|
* Add +capitalize+ option to Inflector.humanizeclaudiob2013-11-061-9/+15
| | | | | | | So strings can be humanized without being capitalized: 'employee_salary'.humanize # => "Employee salary" 'employee_salary'.humanize(capitalize: false) # => "employee salary"
* Fix doc for singularize - `pluralized` => `singularized`Vipul A M2013-08-271-1/+1
|
* Speed up AS::Inflector.underscoreAkira Matsuda2013-07-101-2/+1
| | | | | | | Benchmark: user system total real old 6.090000 0.120000 6.210000 ( 6.202039) new 5.930000 0.110000 6.040000 ( 6.042022)
* Speedup AS::Inflector.camelizeAkira Matsuda2013-07-101-1/+3
| | | | | | | Benchmark: user system total real old 5.960000 0.020000 5.980000 ( 5.981754) new 5.740000 0.030000 5.770000 ( 5.757201)
* Speedup AS::Inflector.deconstantizeAkira Matsuda2013-07-101-1/+1
| | | | | | | Benchmark: user system total real old 0.740000 0.000000 0.740000 ( 0.744358) new 0.550000 0.000000 0.550000 ( 0.553690)
* Merge pull request #10542 from waseem/remove_requireCarlos Antonio da Silva2013-06-251-1/+0
|\ | | | | Remove unnecessary require from active_support/inflector/methods.rb
| * Remove unnecessary require from active_support/inflector/methods.rbWaseem Ahmad2013-05-101-1/+0
| | | | | | | | | | | | `active_support/inflections` already requires `active_support/inflector/inflections`. There's no need to require it in `active_support/inflector/methods`.
* | Updated the doc for const_regexp [ci skip]Arun Agrawal2013-06-151-1/+3
| |
* | Changing const_regexp to check for constant name.Arun Agrawal2013-06-151-0/+3
| | | | | | | | We need to return Regexp.escape(camel_cased_word) if the split is blank.
* | Fix #10932. Treat "" and "::" as invalid on constantizeNikolay Shebanov2013-06-141-1/+6
|/
* Revert "Merge pull request #8156 from fredwu/acronym_fix-master"Steve Klabnik2013-03-161-1/+1
| | | | | | | | | This reverts commit 867dc1700f32aae6f98c4651bd501597e6b52bc0, reversing changes made to 9a421aaa8285cf2a7ecb1af370748b0337818930. This breaks anyone who's using ForceSSL: https://travis-ci.org/rails-api/rails-api/jobs/5556065 Please see comments on #8156 for some discussion.
* Fixed a bug where the inflector would replace camelCase strings and ↵Fred Wu2013-03-171-1/+1
| | | | disregarding specified acronyms, fixes #8015
* Remove unnecessary begin..rescue..end, use only rescueAkira Matsuda2013-01-061-8/+6
|
* Refactor Inflector#ordinal to avoid converting the number twiceCarlos Antonio da Silva2012-11-041-2/+4
|
* update AS/inflector docs [ci skip]Francesco Rodriguez2012-09-141-89/+97
|
* Make ActiveSupport::Inflector locale aware and multilingualDavid Celis2012-07-301-6/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The Inflector is currently not very supportive of internationalized websites. If a user wants to singularize and/or pluralize words based on any locale other than English, they must define each case in locale files. Rather than create large locale files with mappings between singular and plural words, why not allow the Inflector to accept a locale? This patch makes ActiveSupport::Inflector locale aware and uses `:en`` unless otherwise specified. Users will still be provided a list of English (:en) inflections, but they may additionally define inflection rules for other locales. Each list is kept separately and permanently. There is no reason to limit users to one list of inflections: ActiveSupport::Inflector.inflections(:es) do |inflect| inflect.plural(/$/, 's') inflect.plural(/([^aeéiou])$/i, '\1es') inflect.plural(/([aeiou]s)$/i, '\1') inflect.plural(/z$/i, 'ces') inflect.plural(/á([sn])$/i, 'a\1es') inflect.plural(/é([sn])$/i, 'e\1es') inflect.plural(/í([sn])$/i, 'i\1es') inflect.plural(/ó([sn])$/i, 'o\1es') inflect.plural(/ú([sn])$/i, 'u\1es') inflect.singular(/s$/, '') inflect.singular(/es$/, '') inflect.irregular('el', 'los') end 'ley'.pluralize(:es) # => "leyes" 'ley'.pluralize(:en) # => "leys" 'avión'.pluralize(:es) # => "aviones" 'avión'.pluralize(:en) # => "avións" A multilingual Inflector should be of use to anybody that is tasked with internationalizing their Rails application. Signed-off-by: David Celis <david@davidcelis.com>
* make sure the inflection rules are loaded when cherry-picking ↵Xavier Noria2012-06-291-0/+1
| | | | active_support/core_ext/string/inflections.rb [fixes #6884]
* Fix warning: shadowing outer local variable - constant.kennyj2012-05-191-3/+3
|
* Handle case where ancestor is not the end of the chainAndrew White2012-05-191-7/+12
|
* Fix constantize so top level constants are looked up properly.Marc-Andre Lafortune2012-05-191-1/+1
|
* Make constantize look down the ancestor chain (excluding Object)Marc-Andre Lafortune2012-05-191-1/+13
|
* removing unnecessary 'examples' noise from activesupportFrancesco Rodriguez2012-05-131-13/+0
|
* fix typo in ActiveSupport::Inflector#titleizeFrancesco Rodriguez2012-04-281-1/+1
|
* revises the regexp used in titleizeXavier Noria2012-04-071-1/+1
| | | | | | | | | The regexp used in titleize matches saxon genitive and other contractions, only to call capitalize on the captured text and have the apostrophe upcased which yields the apostrophe itself. It is more clear that the regexp matches just what it has to match.
* Updated/changed useless tr/gsubsJurriaan Pruis2012-04-031-1/+1
|
* Fix typoArtyom Bolshakov2012-04-031-1/+1
|
* String#titleize works properly with smart quotes, closes #5584Vasiliy Ermolovich2012-03-261-2/+4
|
* Inflector/constantize - inject method lets us to avoid using another variablehoma2012-02-281-5/+3
|
* prefer tr to gsub for replacing charactersXavier Noria2012-02-121-2/+2
|
* inflection regexp are meant to be applied onceXavier Noria2012-02-121-2/+2
|
* removes redundant argumentXavier Noria2012-02-121-1/+1
|
* boosts inflectionsXavier Noria2012-02-121-1/+1
| | | | | The impact of this change has been measured pluralizing the entire /usr/share/dict/words, showing a 6x speedup
* Add ActiveSupport::Inflector.ordinal and Integer#ordinalTim Gildea2012-02-041-10/+24
|
* There is an "inherit" option on const_get too, why not use it?Semyon Perepelitsa2012-01-311-1/+1
|