aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/object
Commit message (Collapse)AuthorAgeFilesLines
...
* Do not check defined?(CGI) on every call #to_queryprintercu2014-05-131-1/+1
|
* No need the else clauseRafael Mendonça França2014-05-041-2/+0
|
* Merge pull request #14949 from bogdan/empty-hash-array-parameterizationRafael Mendonça França2014-05-041-6/+6
|\ | | | | [Fixes #14948] Hash#to_query: right serialization for empty hash and array
| * [Fixes #14948] Hash#to_query: Changed a way how empty hash and empty array ↵Bogdan Gusiev2014-05-031-6/+6
| | | | | | | | | | | | | | | | | | | | | | are serialized Empty Hash or Array should not present in serialization result {a: []}.to_query # => "" {a: {}}.to_query # => "" For more info see #14948.
* | Remove deprecated file(`active_support/core_ext/object/to_json.rb`) and its ↵Kuldeep Aggarwal2014-05-041-5/+0
|/ | | | test case.
* Object#duplicable?Akshay Vishnoi2014-04-161-0/+3
| | | | | | 1. Improve tests 2. Remove unnecessary constant 3. Add docs for BigDecimal#duplicable?
* Fix #to_json for BasicObject EnumerablesSammy Larbi2014-03-142-2/+2
|
* Go with #presence_in instead of #present_in -- it doesnt sound quite as ↵David Heinemeier Hansson2014-02-241-2/+2
| | | | good, but the closer relationship to #presence over #present is ultimately worth it
* Added Object#present_in to simplify value whitelistingDavid Heinemeier Hansson2014-02-181-0/+12
|
* Fix to_query with empty arrays tooRafael Mendonça França2014-02-061-1/+6
|
* Refatoring the method to avoid shot-circuit returnRafael Mendonça França2014-02-051-4/+7
|
* Fixed "Hash#to_param confused by empty hash values #13892"Hincu Petru2014-02-051-0/+1
|
* Add support for JSON time_precision to Time and DateTimeAndrew White2014-01-261-4/+4
|
* blank? and present? commit to return singletons [Xavier Noria & Pavel Pravosud]Xavier Noria2013-12-281-18/+42
| | | | | | | | | | | | | | | | | | The contract of blank? and present? was in principle to return Object, as we generally do, the test suite and description was consistent with that, but some examples had comments like "# => true". This cannot be unclear, we either fix the examples, or update the contract. Since users may be already assuming singletons due to the examples and the fact that they were returned before 30ba7ee, the safest option seems to be to revise the contract and the implementation of String#blank? The motivation for 30ba7ee was to improve the performance of the predicate, the refactor based on === is on par regarding speed. With this commit we start documenting return types using YARD conventions. We plan to document return types gradually.
* Extracted blank matcher regexp to constantPaul Nikitochkin2013-12-281-1/+3
|
* Process::Status should get a :nodoc: [ci skip]Godfrey Chan2013-11-261-1/+1
|
* Removed the Ruby encoder and switched to using the JSON gemGodfrey Chan2013-11-261-28/+0
| | | | | | | | | Got all the tests passing again. Support for `encode_json` has been removed (and consequently the ability to encode `BigDecimal`s as numbers, as mentioned in the previous commit). Install the `activesupport-json_encoder` gem to get it back.
* Removed support for encoding BigDecimal as a JSON numberGodfrey Chan2013-11-261-8/+1
| | | | | | | | | | This is because the new encoder will no longer support encode_json. Therefore our only choice is to return `to_i` or `to_s` in `BigDecimal#as_json`. Since casting a BigDecimal to an integer is most likely a lossy operation, we chose to encode it as a string. Support for encoding BigDecimal as a string will return via the `activesupport-json_encoder` gem.
* Merge remote-tracking branch 'docrails/master'Xavier Noria2013-11-242-7/+7
|\ | | | | | | | | | | Conflicts: activesupport/lib/active_support/core_ext/hash/deep_merge.rb activesupport/lib/active_support/core_ext/hash/keys.rb
| * The option is called encode_big_decimal_as_string [ci-skip]Godfrey Chan2013-11-151-1/+1
| |
| * Change syntax format for example returned valuesPrem Sichanugrist2013-11-111-6/+6
| | | | | | | | | | | | | | | | | | According to our guideline, we leave 1 space between `#` and `=>`, so we want `# =>` instead of `#=>`. Thanks to @fxn for the suggestion. [ci skip]
* | When Array#as_json and Hash#as_json are called without options, theyGodfrey Chan2013-11-221-2/+2
| | | | | | | | | | should also call #as_json on the children without options (instead of nil)
* | Expand double-negative in String#blank? regexAman Gupta2013-11-201-1/+1
| |
* | Improved compatibility with the stdlib JSON gem.Godfrey Chan2013-11-141-3/+21
|/ | | | | | | | | | | | 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)`.
* Standardize all JSON encoded times to use 3 decimal fractional secondsRyan Glover2013-11-071-2/+2
|
* Move the JSON extension require statements to the right place.Godfrey Chan2013-11-061-0/+7
| | | | | | | 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.
* Do not expose internal state in the public encoder API (i.e. as_json)Godfrey Chan2013-11-061-15/+4
| | | | | | | | | | | | | | | 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
* Eliminate `JSON.{parse,load,generate,dump}` and `def to_json`Godfrey Chan2013-11-051-1/+1
| | | | | | | | | | | | | | | 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)
* Fixed Object#as_json and Struct#as_json with optionsGodfrey Chan2013-11-051-3/+3
| | | | | | | | | | | | 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.
* Require time before monkey-patching itRobin Dupret2013-10-311-0/+1
| | | | | | 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.
* Require bigdecimal before monkey-patching itRobin Dupret2013-10-311-0/+1
| | | | | | | | 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
* Moved all JSON core extensions into core_ext/object/jsonGodfrey Chan2013-09-132-26/+220
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | TL;DR The primary driver is to remove autoload surprise. This is related to #12106. (The root cause for that ticket is that json/add defines Regexp#to_json among others, but here I'll reproduce the problem without json/add.) Before: >> require 'active_support/core_ext/to_json' => true >> //.as_json NoMethodError: undefined method `as_json' for //:Regexp from (irb):3 from /Users/godfrey/.rvm/rubies/ruby-2.0.0-p195/bin/irb:16:in `<main>' >> //.to_json => "\"(?-mix:)\"" >> //.as_json => "(?-mix:)" After: >> require 'active_support/core_ext/to_json' => true >> //.as_json => "(?-mix:)" This is because ActiveSupport::JSON is autoloaded the first time Object#to_json is called, which causes additional core extentions (previously defined in active_support/json/encoding.rb) to be loaded. When someone require 'active_support/core_ext', the expectation is that it would add certain methods to the core classes NOW. The previous behaviour causes additional methods to be loaded the first time you call `to_json`, which could cause nasty surprises and other unplesant side-effects. This change moves all core extensions in to core_ext/json. AS::JSON is still autoloaded on first #to_json call, but since it nolonger include the core extensions, it should address the aforementioned bug. *Requiring core_ext/object/to_json now causes a deprecation warnning*
* Fixes typo in Object#try!Jay Hayes2013-09-101-1/+1
|
* Revert "Merge branch 'master' of github.com:rails/docrails"Vijay Dev2013-08-171-1/+1
| | | | | | | This reverts commit 70d6e16fbad75b89dd1798ed697e7732b8606fa3, reversing changes made to ea4db3bc078fb3093ecdddffdf4f2f4ff3e1e8f9. Seems to be a code merge done by mistake.
* Fixes typo in Object#try!Jay Hayes2013-07-261-1/+1
|
* use destructive sort on array in Hash#to_param for performance gains.Vipul A M2013-05-051-1/+1
| | | | Check https://gist.github.com/vipulnsward/6aad158c06a22f931a71 to see the gains.
* Revert "Object#in? also accepts multiple parameters"Brian Morearty2013-05-011-19/+9
| | | | | | | | | | | | | | | | | | This reverts commit ebf69ab1636df74c76332c53bcd3d8494fb91b45. `in?` must not take multiple parameters because its behavior would be ambiguous: # Test if "B" is included in a list of names with `"B".in?(*names)`: names = ["BMorearty"] "B".in?(*names) # => true names = ["BMorearty","rubyduo"] "B".in?(*names) # => false Conflicts: activesupport/lib/active_support/core_ext/object/inclusion.rb activesupport/test/core_ext/object/inclusion_test.rb
* revamps the RDoc of Object#tryXavier Noria2013-01-281-22/+30
|
* Correct method notation for #acts_like? [ci skip]Doug Yun2013-01-071-4/+4
|
* Instance_variable_names are strings. That is the most important information IMOAkira Matsuda2013-01-081-1/+1
|
* Replace comments' non-breaking spaces with spacesclaudiob2012-12-041-1/+1
| | | | | | | | | | Sometimes, on Mac OS X, programmers accidentally press Option+Space rather than just Space and don’t see the difference. The problem is that Option+Space writes a non-breaking space (0XA0) rather than a normal space (0x20). This commit removes all the non-breaking spaces inadvertently introduced in the comments of the code.
* Revert "remove unnecessary object/conversions file"Xavier Noria2012-10-161-0/+4
| | | | | | | This file is used at least by Active Merchant, its existence is maybe not necessary but no big deal either. This reverts commit ae9b3d7cecd77b9ace38671b183e1a360bf632b6.
* remove unnecessary object/conversions fileNihad Abbasov2012-10-021-4/+0
|
* Merge branch 'master' of github.com:lifo/docrailsVijay Dev2012-09-213-21/+8
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Conflicts: actionmailer/lib/action_mailer/base.rb activesupport/lib/active_support/configurable.rb activesupport/lib/active_support/core_ext/module/deprecation.rb guides/source/action_controller_overview.md guides/source/active_support_core_extensions.md guides/source/ajax_on_rails.textile guides/source/association_basics.textile guides/source/upgrading_ruby_on_rails.md While resolving conflicts, I have chosen to ignore changes done in docrails at some places - these will be most likely 1.9 hash syntax changes.
| * update some AS code examples to 1.9 hash syntax [ci skip]Francesco Rodriguez2012-09-123-21/+8
| |
* | Improve Process::Status#to_jsonSteve Klabnik2012-09-151-0/+8
|/ | | | | | | | | | Because Process::Status has no instance_variables, the ActiveSupport version of #to_json produces {}, which isn't good. Therefore, we implement our own #as_json, which makes it useful again. Fixes #4857
* Bring back changelog entries for Active SupportCarlos Antonio da Silva2012-08-111-2/+2
| | | | Removed in 0228a73b1094a3e19ad291d2ce4789890c09578a, pull request #7310.
* Merge branch 'master' of github.com:lifo/docrailsVijay Dev2012-08-041-2/+5
|\ | | | | | | | | | | Conflicts: activemodel/lib/active_model/secure_password.rb activerecord/lib/active_record/associations/collection_proxy.rb
| * update to_param docs [ci skip]Francesco Rodriguez2012-07-271-2/+5
| |
* | Add Object#try! with the old NoMethodError raising behaviorDavid Heinemeier Hansson2012-07-271-0/+14
| |