aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext
Commit message (Collapse)AuthorAgeFilesLines
* Make ActiveSupport::Inflector locale aware and multilingualDavid Celis2012-07-301-4/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* DRY class_attribute codeAleksandr Zykov2012-07-291-6/+3
|
* Add Object#try! with the old NoMethodError raising behaviorDavid Heinemeier Hansson2012-07-271-0/+14
|
* will now return nil instead of raise a NoMethodError if the receiving ↵David Heinemeier Hansson2012-07-271-1/+4
| | | | object does not implement the method
* Merge branch 'master' of github.com:lifo/docrailsVijay Dev2012-07-151-5/+5
|\
| * use 'use_zone' method in example, instead of reimplementing itJakub Kuźma2012-07-101-5/+5
| |
* | adds a missing require [fixes #6896]Xavier Noria2012-07-152-1/+1
| | | | | | | | | | This file uses Time.zone, which is defined in active_support/core_ext/time/zones.rb.
* | Added time related req files to AS core_ext #6896Aaron Cruz2012-07-143-0/+14
|/ | | | | | This way you can `require 'active_record/core_ext/time'` for example I see these libs are available through `active_record/time` but not individually
* Improve performance of DateTime#seconds_since_unix_epochAndrew White2012-07-021-2/+5
| | | | | | | | | | | | | | | | | | | Calculate the seconds since the UNIX epoch using the difference in Julian day numbers from the epoch date. By reducing the Rational math to just the offset component this gives a significant improvement. Benchmark: Calculating -------------------------------------------- new 27733 i/100ms current 15031 i/100ms new 27737 i/100ms current 15549 i/100ms -------------------------------------------------------- new 548182.1 (±0.9%) i/s - 2745567 in 5.008943s current 216380.9 (±1.6%) i/s - 1082232 in 5.002781s new 510281.9 (±1.2%) i/s - 2551804 in 5.001525s current 219858.3 (±1.8%) i/s - 1103979 in 5.023039s
* Revert "Use strftime to convert DateTime to numeric"Andrew White2012-07-011-1/+2
| | | | | | | There appears to be a bug with DateTime#strftime("%s") on 32-bit platforms. Bug report: http://bugs.ruby-lang.org/issues/6683 This reverts commit 210cd756a628cc19c0d6e44bee8c33dfb2d9d598.
* Make Time#change work with offsets other than UTC or localAndrew White2012-07-011-10/+15
| | | | | Use Time.new to create times where the current offset is not zero or not in the local time zone - closes #4847 and #6651.
* Remove DateTime#to_time overrideAndrew White2012-07-011-14/+0
| | | | | | | | Currently if the offset is not zero then to_time returns self which can lead to errors where a developer assumes that the value is a Time. To solve this we can use the native implementation of DateTime#to_time in Ruby 1.9.3 as it handles offsets properly and is faster than our override.
* Use strftime to convert DateTime to numericAndrew White2012-07-011-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The native implementation of the seconds since the UNIX epoch in strftime is significantly faster than our method. Benchmark: ---------- require 'benchmark/ips' require 'date' require 'time' date = DateTime.civil(1253,7,6,20,4,0) Benchmark.ips do |x| x.report("strftime.to_i") { date.strftime('%s').to_i } x.report("ssue.to_i") { ((date - DateTime.civil(1970)) * 86400).to_i } x.report("strftime.to_f") { date.strftime('%s').to_f } x.report("ssue.to_f") { ((date - DateTime.civil(1970)) * 86400).to_f } end Output: ------- Calculating ------------------------------------- strftime.to_i 26480 i/100ms ssue.to_i 13818 i/100ms strftime.to_f 26561 i/100ms ssue.to_f 14479 i/100ms ------------------------------------------------- strftime.to_i 616937.3 (±2.4%) i/s - 3098160 in 5.024749s ssue.to_i 200108.8 (±6.9%) i/s - 994896 in 4.999278s strftime.to_f 553581.3 (±2.2%) i/s - 2788905 in 5.040397s ssue.to_f 204260.3 (±4.3%) i/s - 1028009 in 5.043072s
* Merge branch 'master' of github.com:lifo/docrailsVijay Dev2012-06-301-7/+0
|\ | | | | | | | | Conflicts: activemodel/lib/active_model/errors.rb
| * Remove mention of `convert_key` now that it's been taken out in ↵Alex Nisnevich2012-06-281-7/+0
| | | | | | | | 1eecd9483b0439ab4913beea36f0d0e2aa0518c7
* | Speed up Hash#transform_keys using Hash#each_keyGrant Hutchins2012-06-271-1/+1
| | | | | | See https://gist.github.com/3007749 for justification
* | Ensure Array#to_sentence does not modify given hashCarlos Antonio da Silva2012-06-261-8/+3
| | | | | | | | | | Also simplify I18n logic for Array#to_sentence, doing only one lookup for all keys and using merge!, instead of one lookup for each option key.
* | Add missing require.Rhett Sutphin2012-06-251-0/+1
|/ | | | | | | | If you selectively require core_exts (e.g., require 'active_support/core_ext/string'), it is possible for 'active_support/core_ext/time/calculations' to be required when `ActiveSupport::TimeWithZone` is not available. If this happens, the next call to Time.=== will fail with a NameError.
* Add prev_quarter and next_quarter method in Time/Date/DateTimeparanoiase Kang2012-06-202-0/+22
|
* Fix doc example for dasherizeMarc-Andre Lafortune2012-06-151-1/+1
|
* Merge branch 'master' of github.com:lifo/docrailsVijay Dev2012-06-141-5/+1
|\
| * remove double hyphen that doesn't allow properly parsingFrancesco Rodriguez2012-06-041-5/+1
| |
* | fix method redefined warning in Ruby2.0Mitsutaka Mimura2012-06-121-5/+7
| | | | | | | | Ruby2.0 already has LoadError#path.
* | no need to to_s here. Both String and Symbol can be interpolated into StringAkira Matsuda2012-06-061-3/+0
| |
* | stop `to_s`ing method namesAkira Matsuda2012-06-061-1/+1
|/ | | | Module#methods are Symbols in Ruby >= 1.9
* Merge branch 'master' of github.com:lifo/docrailsVijay Dev2012-05-304-27/+96
|\
| * some copy edits [ci skip]Vijay Dev2012-05-301-4/+4
| |
| * fix example format and add markup in Module#mattr_accessor documentation [ci ↵Francesco Rodriguez2012-05-291-10/+10
| | | | | | | | skip]
| * Updates Array conversions method documentations and clean upsAlvaro Pereyra2012-05-281-4/+0
| |
| * fix empty lines [ci skip]Francesco Rodriguez2012-05-282-2/+0
| |
| * Merge branch 'master' of github.com:lifo/docrailsAlvaro Pereyra2012-05-2826-61/+245
| |\
| | * remove :nodoc: from Class#subclasses [ci skip]Francesco Rodriguez2012-05-281-4/+10
| | |
| | * add :locale option to Array#to_sentence documentation [ci skip]Francesco Rodriguez2012-05-281-0/+27
| | |
| | * add examples to Array#to_sentence [ci skip]Francesco Rodriguez2012-05-281-4/+24
| | |
| | * update documentation of array/access methods [ci skip]Francesco Rodriguez2012-05-281-8/+16
| | |
| * | Updates documentation with cleaner examples and texts [ci skip]Alvaro Pereyra2012-05-282-1/+15
| | |
| * | Remove blank trailing commentsHenrik Hodne2012-05-2015-30/+0
| | | | | | | | | | | | | | | | | | | | | For future reference, this is the regex I used: ^\s*#\s*\n(?!\s*#). Replace with the first match, and voilà! Note that the regex matches a little bit too much, so you probably want to `git add -i .` and go through every single diff to check if it actually should be changed.
* | | Review requires from number helperCarlos Antonio da Silva2012-05-281-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | Some of these requires are now only necessary in ActiveSupport::NumberHelper. Add hash/keys require due to symbolize_keys usage in number helpers. Also remove some whitespaces. Closes #6414
* | | remove unnecessary requireSergey Nartimov2012-05-282-4/+0
| | | | | | | | | | | | | | | AS::Multibyte are no longer required by access and filters string core extensions.
* | | Moving NumberHelpers from ActionView to ActiveSupportAndrew Mutz2012-05-273-2/+143
| |/ |/|
* | Merge branch 'master' of github.com:lifo/docrailsVijay Dev2012-05-272-14/+32
|\ \
| * | update Module#mattr_accessor documentation [ci skip]Francesco Rodriguez2012-05-261-6/+6
| | |
| * | update Hash documentation with 1.9 syntax [ci skip]Francesco Rodriguez2012-05-261-8/+16
| | |
| * | add examples to Hash#deep_stringify_keys and Hash#deep_symbolize_keys [ci skip]Francesco Rodriguez2012-05-261-0/+10
| | |
* | | Update the documentation and add CHANGELOG entryRafael Mendonça França2012-05-261-1/+1
|/ /
* | Merge branch 'master' of github.com:lifo/docrailsVijay Dev2012-05-263-12/+15
|\ \
| * | Fix unbalanced braces in Hash#typecast_xml_value internal commentAlexey Vakhov2012-05-251-1/+1
| | |
| * | Clean Date#beginning_of_month descriptionAlexey Vakhov2012-05-251-1/+1
| | | | | | | | | | | | | | | Unnecessary peace of text was injected at 507da04a149b44e20c5a0ba72a218fe1762b6baf by mistake.
| * | Update examples of Array #in_groups and #in_groups_ofAlexey Vakhov2012-05-251-10/+13
| | | | | | | | | | | | | | | Examples should be not square to visually underline a difference between Array#in_groups and Array#in_groups_of.
* | | Reorder deep_symbolize_keys methodsMark McSpadden2012-05-251-7/+7
| | |