Created
April 22, 2017 10:49
-
-
Save royratcliffe/1b42ac346538a531fe8ef42cd7c22e64 to your computer and use it in GitHub Desktop.
Pretty JSON encoding for Active Support
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'active_support/json/encoding' | |
module ActiveSupport | |
module JSON | |
module Encoding | |
class JSONGemEncoder | |
# Replaces the JSON gem encoder's string-ify method with a | |
# pretty-generator implementation. Just clobbers the original method, | |
# so makes assumptions about method name, arguments and | |
# implementation details. That makes it Rails version dependent. | |
# Useful just for development only. | |
def stringify jsonified | |
::JSON.pretty_generate jsonified, quirks_mode: true, max_nesting: false | |
end | |
end | |
end | |
end | |
end if Rails.env.development? && Gem::Dependency.new('rails', '~> 5.0.2').match?('rails', Rails.version) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cheers ZzZombo, glad to know it still works.