Commit Graph

3522 Commits

Author SHA1 Message Date
Xavier Noria
447b6a4e67 removes usage of Object#in? from the code base (the method remains defined by Active Support)
Selecting which key extensions to include in active_support/rails
made apparent the systematic usage of Object#in? in the code base.
After some discussion in

    5ea6b0df9a

we decided to remove it and use plain Ruby, which seems enough
for this particular idiom.

In this commit the refactor has been made case by case. Sometimes
include? is the natural alternative, others a simple || is the
way you actually spell the condition in your head, others a case
statement seems more appropriate. I have chosen the one I liked
the most in each case.
2012-08-06 00:30:02 +02:00
Vijay Dev
3d3fa165e4 Merge branch 'master' of github.com:lifo/docrails
Conflicts:
	activemodel/lib/active_model/secure_password.rb
	activerecord/lib/active_record/associations/collection_proxy.rb
2012-08-04 15:18:35 +05:30
Xavier Noria
077372b20d load active_support/deprecation in active_support/rails 2012-08-02 21:59:23 +02:00
Xavier Noria
4aee8dd486 load active_support/core_ext/module/delegation in active_support/rails 2012-08-02 21:59:23 +02:00
Xavier Noria
5e1b92044c load active_support/core_ext/class/attribute in active_support/rails 2012-08-02 21:59:23 +02:00
Xavier Noria
64bc8447c2 load active_support/concern in active_support/rails 2012-08-02 21:59:23 +02:00
Xavier Noria
47396a9db8 load active_support/dependencies/autoload in active_support/rails 2012-08-02 21:59:23 +02:00
Xavier Noria
5ea6b0df9a load active_support/core_ext/object/inclusion in active_support/rails 2012-08-02 21:59:22 +02:00
Xavier Noria
8f58d6e507 load active_support/core_ext/object/blank in active_support/rails 2012-08-02 21:59:22 +02:00
Xavier Noria
1a7b2e8fad defines a private require-hub active_support/rails
This is a private place to put those AS features that are used
by every component. Nowadays we cherry-pick individual files
wherever they are used, but that it is not worth the effort
for stuff that is going to be loaded for sure sooner or later,
like blank?, autoload, concern, etc.
2012-08-02 21:59:22 +02:00
Santiago Pastorino
b6ab441772 html_escape should escape single quotes
https://www.owasp.org/index.php/XSS_%28Cross_Site_Scripting%29_Prevention_Cheat_Sheet#RULE_.231_-_HTML_Escape_Before_Inserting_Untrusted_Data_into_HTML_Element_Content
Closes #7215
2012-07-31 22:26:52 -03:00
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
Francesco Rodriguez
0340493694 update to_param docs [ci skip] 2012-07-27 21:02:08 -05: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