Commit Graph

4239 Commits

Author SHA1 Message Date
Alexey Chernenkov
0e953c94b1 Unify cattr_* interface: allow to pass a block to cattr_reader.
Example:

    class A
      cattr_reader(:defr) { 'default_reader_value' }
    end
    A.defr # => 'default_reader_value'
2013-11-15 19:54:51 +06:00
Godfrey Chan
0f33d70e89 Improved compatibility with the stdlib JSON gem.
Previously, calling `::JSON.{generate,dump}` sometimes causes
unexpected failures such as intridea/multi_json#86.

`::JSON.{generate,dump}` now bypasses the ActiveSupport JSON encoder
completely and yields the same result with or without ActiveSupport.
This means that it will **not** call `as_json` and will ignore any
options that the JSON gem does not natively understand. To invoke
ActiveSupport's JSON encoder instead, use `obj.to_json(options)` or
`ActiveSupport::JSON.encode(obj, options)`.
2013-11-14 15:46:43 -08:00
Dmitry Vorotilin
1e62457a6d Clean up require ‘active_support/deprecation’ and remove circular require 2013-11-14 12:59:56 +04:00
Guillermo Iguaran
7dc3baa96b Get rid of unused variable 2013-11-14 01:57:09 -05:00
Guillermo Iguaran
416a9c73d3 Merge pull request #12882 from charliesome/use-rescue-splat-in-suppress
Use rescue with a splat rather and catching all exceptions and manually filtering in Kernel#suppress
2013-11-13 19:37:04 -08:00
Charlie Somerville
425f4829bd Use rescue with a splat rather and catching all and filtering 2013-11-13 19:34:15 -08:00
Xavier Noria
92f11ddd50 Merge pull request #12857 from kuldeepaggarwal/f-indentation
updated documentation for Integer [ci skip]
2013-11-11 11:15:33 -08:00
Kuldeep Aggarwal
7d4733ac4c updated documentation for Integer 2013-11-12 00:06:39 +05:30
Rafael Mendonça França
eb6dd34136 Merge pull request #12854 from kuldeepaggarwal/f-indentation
methods and outputs indented [ci skip]
2013-11-11 10:00:49 -08:00
KD
bf8b9925f4 documentation updated for Hashes [ci skip] 2013-11-11 22:31:55 +05:30
Guillermo Iguaran
15ef6bed18 Merge pull request #12842 from kuldeepaggarwal/array_split
Speed up Array#split when block is passed
2013-11-11 00:02:50 -08:00
KD
4aadd160ff Speed up Array#split
Ruby 2.0.0p247
Rehearsal ---------------------------------------
old  10.670000   0.150000  10.820000 ( 10.822651)
new   8.520000   0.050000   8.570000 (  8.571825)
----------------------------- total: 19.390000sec

          user     system      total        real
old  10.620000   0.170000  10.790000 ( 10.790409)
new   8.570000   0.110000   8.680000 (  8.686051)
2013-11-11 13:31:26 +05:30
Yves Senn
d17e79b0f3 Merge pull request #12841 from kuldeepaggarwal/in-group-documentation
Array#in_groups: documentation updated [ci skip]
2013-11-10 23:47:54 -08:00
Guillermo Iguaran
5b1221347d Merge pull request #12839 from kuldeepaggarwal/array_split
Array#split preserving the calling array
2013-11-10 22:47:31 -08:00
KD
8e5b6e6853 Array#in_groups: documentation updated 2013-11-11 11:46:20 +05:30
KD
133399482c Array#split preserving the calling array 2013-11-11 11:32:30 +05:30
Guillermo Iguaran
281f488fff Use the method provided by minitest to make tests order dependent 2013-11-09 17:07:26 -05:00
Ryan Glover
a64d4e85e3 Standardize all JSON encoded times to use 3 decimal fractional seconds 2013-11-07 10:43:51 -05:00
Yves Senn
1dfe05f98e Merge pull request #12771 from bogdan/patch-1
Fix AS::TimeWithZone#as_json docs [ci skip]
2013-11-07 01:22:32 -08:00
Bogdan Gusiev
68bee763bf Fix AS::TimeWithZone#as_json docs
According to 28ab79d7c579fa1d76ac868be02b38b02818428a
2013-11-07 11:18:52 +02:00
Godfrey Chan
0b7c6d58c0 Move the JSON extension require statements to the right place.
In #12203, the JSON core extensions were moved into the `core_ext`
folder. Unfortunately, there are some corresponding requires that
were left behind. The problem is partially addressed in #12710, this
commit fixes the rest.
2013-11-06 18:18:06 -08:00
Godfrey Chan
798881ecd4 Do not expose internal state in the public encoder API (i.e. as_json)
See [1] for why this is not a good idea.

As part of this refactor, circular reference protection in as_json has
been removed and the corresponding error class has been deprecated.

As discussed with @jeremy, circular reference error is considered
programmer errors and protecting against it is out of scope for
the encoder.

This is again based on the excellent work by @sergiocampama in #11728.

[1]: https://github.com/intridea/multi_json/pull/138#issuecomment-24468223
2013-11-06 17:16:11 -08:00
Godfrey Chan
6da5ff45c6 Moved AS::JSON::DATE_REGEX as it's only used for decoding 2013-11-06 17:15:18 -08:00
Aaron Patterson
5584ddc43d Stop using method missing for singleton delegation.
This saved about 46 array allocations per request on an extremely simple
application.  The delegation happened in the notification subsystem
which is a hotspot, so this should result in even more savings with
larger apps.

Squashed commit of the following:

commit 41eef0d1479526f7de25fd4391d98e61c126d9f5
Author: Aaron Patterson <aaron.patterson@gmail.com>
Date:   Wed Nov 6 16:32:31 2013 -0800

    speed up notifications

commit 586b4a18656f66fb2c518fb8e8fee66a016e8ae6
Author: Aaron Patterson <aaron.patterson@gmail.com>
Date:   Wed Nov 6 16:31:05 2013 -0800

    speed up runtime registry methods

commit b67d074cb4314df9a88438f785868cef77e583d7
Author: Aaron Patterson <aaron.patterson@gmail.com>
Date:   Wed Nov 6 16:28:12 2013 -0800

    change method name and make it public
2013-11-06 16:32:47 -08:00
claudiob
c61544c781 Add +capitalize+ option to Inflector.humanize
So strings can be humanized without being capitalized:

    'employee_salary'.humanize                    # => "Employee salary"
    'employee_salary'.humanize(capitalize: false) # => "employee salary"
2013-11-06 13:03:46 -08:00
Godfrey Chan
ff1192fea4 Eliminate JSON.{parse,load,generate,dump} and def to_json
JSON.{dump,generate} offered by the JSON gem is not compatiable with
Rails at the moment and can cause a lot of subtle bugs when passed
certain data structures. This changed all direct usage of the JSON gem
in internal Rails code to always go through AS::JSON.{decode,encode}.

We also shouldn't be implementing `to_json` most of the time, and
these occurances are replaced with an equivilent `as_json`
implementation to avoid problems down the road.

See [1] for all the juicy details.

[1]: intridea/multi_json#138 (comment)
2013-11-05 22:26:45 -08:00
Godfrey Chan
134c1156dd Fixed Object#as_json and Struct#as_json with options
These methods now takes the same options as Hash#as_json, for example:

    struct = Struct.new(:foo, :bar).new
    struct.foo = "hello"
    struct.bar = "world"
    json = struct.as_json(only: [:foo]) # => {foo: "hello"}

This is extracted from PR #11728 from @sergiocampama, see also the
discussion in #11460.
2013-11-05 19:22:03 -08:00
David Heinemeier Hansson
1c35f9331c Aesthetics 2013-11-03 12:41:58 -08:00
David Heinemeier Hansson
423249504a Added Numeric#in_milliseconds, like 1.hour.in_milliseconds, so we can feed them to JavaScript functions like getTime(). 2013-11-02 15:40:16 -07:00
Arun Agrawal
816126862e Warnings removed for ruby trunk
Same as 4d4ff531b8807ee88a3fc46875c7e76f613956fb
2013-11-01 09:49:57 +01:00
Yves Senn
1adcebdb58 Merge pull request #12713 from utenmiki/document
Add Rdoc document for Array#forty_two [ci skip]
2013-11-01 01:01:32 -07:00
Aaron Patterson
4d4ff531b8 clean up some warnings on trunk ruby 2013-10-31 11:47:51 -07:00
utenmiki
3f79d84230 Add Rdoc document for Array#forty_two 2013-10-31 23:20:15 +09:00
Robin Dupret
e3d775f00a Require time before monkey-patching it
Same as #12710 but for the time module this time. This time it should
fix the Active Model test suite in isolation avoiding a TypeError to
be raised about the superclass of the DateTime object.
2013-10-31 13:46:23 +01:00
Robin Dupret
9d6d07ddf4 Require bigdecimal before monkey-patching it
If we try to monkey-patch the class before requiring it, then a
"superclass mismatch" (TypeError) error is raised and the build can't
run correctly.

Fixes #12708
2013-10-31 12:19:48 +01:00
Godfrey Chan
1fb7969154 Raise an error when AS::JSON.decode is called with options
Rails 4.1 has switched away from MultiJson, and does not currently
support any options on `ActiveSupport::JSON.decode`. Passing in
unsupported options (i.e. any non-empty options hash) will now raise
an ArgumentError.

Rationale:

1. We cannot guarantee the underlying JSON parser won't change in the
   future, hence we cannot guarantee a consistent set of options the
   method could take

2. The `json` gem, which happens to be the current JSON parser, takes
   many dangerous options that is irrelevant to the purpose of AS's
   JSON decoding API

3. To reserve the options hash for future use, e.g. overriding default
   global options like ActiveSupport.parse_json_times

This change *DOES NOT* introduce any changes in the public API. The
signature of the method is still decode(json_text, options). The
difference is this method previously accepted undocumented options
which does different things when the underlying adapter changes. It
now correctly raises an ArgumentError when it encounters options that
it does not recognize (and currently it does not support any options).
2013-10-30 10:56:00 -07:00
Jeremy Kemper
dae66a0c97 Merge pull request #12203 from chancancode/eager_load_json
Eagerload active_support/json/encoding in active_support/core_ext/object/to_json
2013-10-30 10:43:43 -07:00
Aaron Patterson
45318e4010 use a thread local rather than a queue so events are in the right order 2013-10-30 10:33:36 -07:00
Rafael Mendonça França
f18cf8e488 Merge pull request #11785 from grosser/grosser/file-unless-exist
support :unless_exist for FileCache

Conflicts:
	activesupport/CHANGELOG.md
	activesupport/test/caching_test.rb
2013-10-28 19:09:22 -02:00
Aaron Patterson
f78c5fbb96 use a queue rather than a list. fixes #12069 2013-10-28 13:42:49 -07:00
Yves Senn
c1ae3d7731 fix typo in comment [ci skip]. 2013-10-28 10:08:55 +01:00
Antonio Santos
f13fce617d slice! should not remove default hash value/proc 2013-10-24 09:17:35 +02:00
Dmitry Vorotilin
6d6300bcad Add missed require making enable_warnings available 2013-10-15 15:00:06 +04:00
Rafael Mendonça França
44ef5a83c8 Merge pull request #12534 from vipulnsward/minor_number_helper_perfs
Minor Refactoring to `NumberHelper#number_to_human`
2013-10-14 19:21:57 -07:00
Vipul A M
8b14a6b768 Fix singleton_class?
Due to changes from http://bugs.ruby-lang.org/projects/ruby-trunk/repository/revisions/39628 current `singleton_class?` implementation fails.
Changed based on reference from http://bugs.ruby-lang.org/issues/7609
2013-10-15 00:07:16 +05:30
Vipul A M
67c2525d59 Minor Refactoring to NumberHelper#number_to_human
* Use destructive `map` and `sort_by` to save extra object creation.
* Create `INVERTED_DECIMAL_UNITS.invert` constant instead of repeatedly doing `DECIMAL_UNITS.invert`
2013-10-14 23:52:06 +05:30
Jeremy Kemper
365110196a Revert "Merge pull request #12480 from iwiznia/master"
This reverts commit e5f5a838b96a362534d9bb60d02334439ed9784c, reversing
changes made to d7567f3290a50952494e9213556a1f283a6cf3a0.
2013-10-11 13:05:29 -07:00
Ionatan Wiznia
90871f7198 flatten and flatten! methods for ActiveSupport::Duration 2013-10-11 12:50:23 +02:00
Xavier Noria
7dfbe58c70 revises the docs of require_dependency [ci skip] 2013-10-01 10:10:53 +02:00
Xavier Noria
2254615bff Merge pull request #12412 from bf4/allow_pathname_for_require_dependency
Allow Pathname for require dependency
2013-09-30 23:22:11 -07:00