Module: Jsonnet

Defined in:
lib/jsonnet.rb,
lib/jsonnet/vm.rb,
lib/jsonnet/version.rb,
ext/jsonnet/jsonnet.c

Defined Under Namespace

Classes: EvaluationError, FormatError, UnsupportedEncodingError, VM

Constant Summary collapse

VERSION =
"0.5.3"
STRING_STYLE_DOUBLE =
rb_str_new_cstr("d")
STRING_STYLE_SINGLE =
rb_str_new_cstr("s")
STRING_STYLE_LEAVE =
rb_str_new_cstr("l")
COMMENT_STYLE_HASH =
rb_str_new_cstr("h")
COMMENT_STYLE_SLASH =
rb_str_new_cstr("s")
COMMENT_STYLE_LEAVE =
rb_str_new_cstr("l")

Class Method Summary collapse

Class Method Details

.evaluate(jsonnet, jsonnet_options: {}, json_options: {}) ⇒ Hash

Note:

This method runs Jsonnet::VM#evaluate and runs the string output through JSON.parse so those should be looked at for furhter details

Evaluates a string of Jsonnet and returns a hash of the resulting JSON

Parameters:

  • jsonnet (String)

    Jsonnet source string, ideally in UTF-8 encoding

  • jsonnet_options (Hash) (defaults to: {})

    A hash of options to for Jsonnet::VM. Available options are: filename, multi, import_callback, gc_growth_triger, gc_min_objects, max_stack, max_trace

  • json_options (Hash) (defaults to: {})

    Options supported by JSON.parse

Returns:

  • (Hash)

    The JSON representation as a hash

Raises:

  • (UnsupportedOptionError)

    Raised when an option passed is unsupported by Jsonnet::VM



23
24
25
26
# File 'lib/jsonnet.rb', line 23

def evaluate(jsonnet, jsonnet_options: {}, json_options: {})
  output = VM.evaluate(jsonnet, jsonnet_options)
  JSON.parse(output, json_options)
end

.versionString

Returns the version of the underlying C++ implementation of Jsonnet.

Returns:

  • (String)


13
14
15
16
17
# File 'ext/jsonnet/jsonnet.c', line 13

static VALUE
jw_s_version(VALUE mod)
{
    return rb_usascii_str_new_cstr(jsonnet_version());
}

.load(path, jsonnet_options: {}, json_options: {}) ⇒ Hash

Note:

This method runs Jsonnet::VM#evaluate_file and runs the string output through JSON.parse so those should be looked at for furhter details

Loads a Jsonnet file and returns a hash of the resulting JSON

Parameters:

  • path (String)

    path to the jsonnet file

  • jsonnet_options (Hash) (defaults to: {})

    A hash of options to for Jsonnet::VM. Available options are: encoding, multi, import_callback, gc_growth_triger, gc_min_objects, max_stack, max_trace

  • json_options (Hash) (defaults to: {})

    Options supported by JSON.parse

Returns:

  • (Hash)

    The JSON representation as a hash

Raises:

  • (UnsupportedOptionError)

    Raised when an option passed is unsupported by Jsonnet::VM



43
44
45
46
# File 'lib/jsonnet.rb', line 43

def load(path, jsonnet_options: {}, json_options: {})
  output = VM.evaluate_file(path, jsonnet_options)
  JSON.parse(output, json_options)
end