diff options
author | Ryunosuke Sato <tricknotes.rs@gmail.com> | 2016-06-25 21:50:15 +0900 |
---|---|---|
committer | Ryunosuke Sato <tricknotes.rs@gmail.com> | 2016-06-25 21:50:16 +0900 |
commit | abbf00e5830141d3eda451e10bf12c3dccf668ec (patch) | |
tree | d863da20504ec422287749b57c862f217483d95f /activesupport/lib | |
parent | 6da5f6b451e27d59c2492e504350d0fc70c37e3a (diff) | |
download | rails-abbf00e5830141d3eda451e10bf12c3dccf668ec.tar.gz rails-abbf00e5830141d3eda451e10bf12c3dccf668ec.tar.bz2 rails-abbf00e5830141d3eda451e10bf12c3dccf668ec.zip |
Define `Pathname#as_json`
When the Pathname object is converted as JSON,
it should be a string that means itself.
Expected:
```
>> Pathname.new('/path/to/somewhere.txt').as_json
"/path/to/somewhere.txt"
```
Actual:
```
>> Pathname.new('/path/to/somewhere.txt').as_json
{"path"=>"/path/to/somewhere.txt"}
```
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/core_ext/object/json.rb | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/object/json.rb b/activesupport/lib/active_support/core_ext/object/json.rb index 32a41eafe4..363bde5a68 100644 --- a/activesupport/lib/active_support/core_ext/object/json.rb +++ b/activesupport/lib/active_support/core_ext/object/json.rb @@ -2,6 +2,7 @@ require 'json' require 'bigdecimal' require 'uri/generic' +require 'pathname' require 'active_support/core_ext/big_decimal/conversions' # for #to_s require 'active_support/core_ext/hash/except' require 'active_support/core_ext/hash/slice' @@ -199,6 +200,12 @@ class URI::Generic #:nodoc: end end +class Pathname #:nodoc: + def as_json(options = nil) + to_s + end +end + class Process::Status #:nodoc: def as_json(options = nil) { :exitstatus => exitstatus, :pid => pid } |