module JSONPrettyGenerate

Constants

VERSION

Public Class Methods

call(obj) { |with_indifferent_access| ... } click to toggle source
# File lib/json_pretty_generate.rb, line 8
def self.call(obj)
  return unless [Hash, String].include?(obj.class)

  if obj.is_a? String
    begin
      obj = JSON.parse(obj)
    rescue JSON::ParserError
      return obj
    end
  end

  obj = yield(obj.with_indifferent_access) if block_given?

  JSON.pretty_generate(obj)
end