Commit Graph

3510 Commits

Author SHA1 Message Date
José Valim
13af5aceff Merge pull request #7197 from davidcelis/i18n_inflector
Make ActiveSupport::Inflector locale aware and multilingual
2012-07-31 05:46:25 -07:00
David Celis
7db0b073fe Make ActiveSupport::Inflector locale aware and multilingual
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>
2012-07-30 21:49:18 -07:00
José Valim
8601f733af Revert "DRY class_attribute code"
class_attribute is a building block and using define_method
can be much slower for such basic method definitions.

This reverts commit d59208d7032e2be855a89ad8d4685cc08dd7cdb3.
2012-07-30 08:19:15 +02:00
Aaron Patterson
af0a9f9eef added live responses which can be written and read in separate threads 2012-07-29 21:43:05 -07:00
Aleksandr Zykov
d59208d703 DRY class_attribute code 2012-07-29 22:33:39 +06:00
David Heinemeier Hansson
04998cd0c9 Add Object#try! with the old NoMethodError raising behavior 2012-07-27 12:33:02 -05:00
David Heinemeier Hansson
99ea1a875b will now return nil instead of raise a NoMethodError if the receiving object does not implement the method 2012-07-27 12:22:38 -05:00
Anatoly Makarevich
103a31391b fix typo in documentation 2012-07-26 22:44:36 +04:00
Francesco Rodriguez
12ae9d618e fixing :nodoc:s in AS::JSON::Encoding 2012-07-21 16:38:02 -05:00
Rafael Mendonça França
f5d0e3d760 +"foo"+ doesn't generate code tag [ci skip] 2012-07-21 14:12:01 -03:00
Rafael Mendonça França
f1a317b8e9 Lets be consistent with whitespaces at documentation 2012-07-21 14:05:19 -03:00
Xavier Noria
db4fdb58ef makes a pass over the API of ActiveSupport::HashWithIndifferentAccess 2012-07-21 13:03:19 +02:00
Xavier Noria
98f4aee8da Hash#fetch(fetch) is not the same as doing hash[key] 2012-07-21 08:04:37 +02:00
Piotr Niełacny
b0ab8dc0b2 Use join without default separator
Use lstrip method
2012-07-20 08:16:58 +02:00
Aaron Patterson
e482100d6e Revert "Merge pull request #7084 from LTe/logger_default_separator"
This reverts commit c08f30ff5fcda7e07cd9275a073acb2091e4b3f7, reversing
changes made to e243a8a32eb4c8777f07ca4b974bd7e38d9477d3.
2012-07-18 13:32:21 -07:00
Piotr Niełacny
dc97a9a9dd Don't use default separator
When the default separator is set logger will create incorrect output
2012-07-18 09:44:45 +02:00
Vijay Dev
a80e1e437e Merge branch 'master' of github.com:lifo/docrails 2012-07-15 19:36:19 +05:30
Xavier Noria
aa6f5120a7 adds a missing require [fixes #6896]
This file uses Time.zone, which is defined in
active_support/core_ext/time/zones.rb.
2012-07-15 00:44:30 +02:00
Aaron Cruz
4940dc2c50 Added time related req files to AS core_ext #6896
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
2012-07-14 14:29:46 +02:00
Jakub Kuźma
897f8f5453 use 'use_zone' method in example, instead of reimplementing it 2012-07-10 10:02:28 +02:00
Aaron Patterson
d481170251 deprecate describe without a block.
minitest/spec provides `describe`, so deprecate the rails version and
have people use the superclass version
2012-07-09 13:13:59 -07:00
Aaron Patterson
5921cf0b45 we still need describe as the implementation differs from minitest 2012-07-08 14:51:57 -07:00
Aaron Patterson
22bc12ec37 minitest provides "it" and "describe"
Remove rails implementation of describe, alias "test" to "it"
2012-07-08 10:54:21 -07:00
Aaron Patterson
3270156049 minitest is a gem dep, so remove this conditional 2012-07-08 10:50:21 -07:00
Aaron Patterson
6f74d36c42 activesupport gem dependencies should reflect the versions we actually use 2012-07-04 11:16:21 -07:00
Carlos Antonio da Silva
f3353895a0 Kill not used constant since removal of runner method
Runner method was removed in ada571bfcdbad669ae43a4dd18277ef227680a0b.
2012-07-03 21:02:49 -03:00
Aaron Patterson
ada571bfcd remove the runner method copied from minitest 2012-07-03 14:28:28 -07:00
Aaron Patterson
089da2e54d hook mocha in through m/t before_setup, after_teardown hooks 2012-07-03 14:28:28 -07:00
Xavier Noria
65dc45ea2d explains why the file update checker ignores mtimes in the future, plus a little refactor for the same price 2012-07-02 23:56:13 +02:00
Andrew White
822c858a1a Improve performance of DateTime#seconds_since_unix_epoch
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
2012-07-02 07:05:17 +01:00
Andrew White
d441de3697 Revert "Use strftime to convert DateTime to numeric"
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.
2012-07-01 17:27:49 +01:00
Andrew White
98b46bf5e2 Make Time#change work with offsets other than UTC or local
Use Time.new to create times where the current offset is not zero or
not in the local time zone - closes #4847 and #6651.
2012-07-01 09:11:21 +01:00
Andrew White
73bddd12a4 Remove rescue clause from ActiveSupport::TimeZone#to_f
Time#at no longer raises an error for large values so we can remove
the rescue clause from ActiveSupport::TimeZone#to_f.
2012-07-01 08:48:40 +01:00
Andrew White
c685d12c19 Remove DateTime#to_time override
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.
2012-07-01 08:02:41 +01:00
Andrew White
210cd756a6 Use strftime to convert DateTime to numeric
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
2012-07-01 07:55:41 +01:00
Vijay Dev
6b9d1a0db2 Merge branch 'master' of github.com:lifo/docrails
Conflicts:
	activemodel/lib/active_model/errors.rb
2012-06-30 23:15:22 +05:30
Xavier Noria
58c83d4c61 make sure the inflection rules are loaded when cherry-picking active_support/core_ext/string/inflections.rb [fixes #6884] 2012-06-29 21:29:14 +02:00
abonec
20519efa6e fix FileUpdateChecker when file has wrong mtime (from future) 2012-06-29 19:43:33 +04:00
Alex Nisnevich
32c28e8214 Remove mention of convert_key now that it's been taken out in 1eecd9483b0439ab4913beea36f0d0e2aa0518c7 2012-06-28 20:10:58 -07:00
Grant Hutchins
f6bedc960d Speed up Hash#transform_keys using Hash#each_key
See https://gist.github.com/3007749 for justification
2012-06-27 20:09:30 -04:00
Carlos Antonio da Silva
60571b8539 Ensure Array#to_sentence does not modify given hash
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.
2012-06-26 22:05:56 -03:00
Bogdan Gusiev
88230b7cf7 AS::Callbacks: deprecate monkey patch code
Deprecate usage of filter object with #before and #after
methods as around callback
2012-06-26 09:21:36 +03:00
Rhett Sutphin
e6d4dc3ec4 Add missing require.
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.
2012-06-25 14:54:40 -05:00
Carlos Antonio da Silva
36d863ce51 Move constants to the top, remove freeze 2012-06-24 19:30:05 -03:00
Carlos Antonio da Silva
06d50b9d73 Remove some not used variables and improve code a bit 2012-06-24 19:30:05 -03:00
benolee
008023c29a correct line numbers for reader and writer methods 2012-06-24 14:39:49 -05:00
Francesco Rodriguez
bc7ac33846 add :nodoc: to internal implementations [ci skip] 2012-06-22 16:29:59 -05:00
Vijay Dev
35ee8fa3d8 Merge branch 'master' of github.com:lifo/docrails 2012-06-22 22:15:27 +05:30
Vijay Dev
6285675db1 fixes a few mistakes in api docs [ci skip] 2012-06-22 22:14:29 +05:30
Aaron Patterson
26a4e5e60e logger is a singleton, just flush the singleton 2012-06-20 14:21:23 -07:00