Method: Jsonify::Builder#compile!

Defined in:
lib/jsonify/builder.rb

#compile!Object

Compiles the JSON objects into a string representation. If initialized with :verify => true, the compiled result will be verified by attempting to re-parse it using MultiJson.load. If initialized with :format => :pretty, the compiled result will be parsed and encoded via MultiJson.dump(<json>, :pretty => true) This method can be called without any side effects. You can call compile! at any time, and multiple times if desired.

Raises:

  • (TypeError)

    only if :verify is set to true

  • (JSON::ParseError)

    only if :verify is set to true



76
77
78
79
80
81
# File 'lib/jsonify/builder.rb', line 76

def compile!
  result = (@stack[0] || {}).encode_as_json
  MultiJson.load(result) if @verify
  result = MultiJson.dump(MultiJson.load(result), :pretty => true) if @pretty
  result
end