Class: Jsonnet::VM
- Inherits:
-
Data
- Object
- Data
- Jsonnet::VM
- Defined in:
- lib/jsonnet/vm.rb,
ext/jsonnet/jsonnet.c
Class Method Summary collapse
Instance Method Summary collapse
- #debug_ast=(val) ⇒ Object
-
#evaluate(jsonnet, filename: "(jsonnet)", multi: false) ⇒ String
Evaluates Jsonnet source.
-
#evaluate_file(filename, encoding: Encoding.default_external, multi: false) ⇒ String
Evaluates Jsonnet file.
-
#ext_var(key, val) ⇒ Object
Binds an external variable to a value.
- #gc_growth_trigger=(val) ⇒ Object
- #gc_min_objects=(val) ⇒ Object
-
#handle_import {|base, rel| ... } ⇒ Object
Lets the given block handle “import” expression of Jsonnet.
-
#import_callback=(callback) ⇒ Object
Sets a custom way to resolve “import” expression.
- #max_stack=(val) ⇒ Object
- #max_trace=(val) ⇒ Object
-
#string_output=(val) ⇒ Object
Let #evalutae and #evaluate_file return a raw String instead of JSON-encoded string if val is true.
Class Method Details
.new ⇒ Object
138 139 140 141 142 143 144 145 146 |
# File 'ext/jsonnet/jsonnet.c', line 138
static VALUE
vm_s_new(VALUE mod)
{
struct jsonnet_vm_wrap *vm;
VALUE self = TypedData_Make_Struct(cVM, struct jsonnet_vm_wrap, &jsonnet_vm_type, vm);
vm->vm = jsonnet_make();
vm->callback = Qnil;
return self;
}
|
Instance Method Details
#debug_ast=(val) ⇒ Object
346 347 348 349 350 351 352 353 |
# File 'ext/jsonnet/jsonnet.c', line 346
static VALUE
vm_set_debug_ast(VALUE self, VALUE val)
{
struct jsonnet_vm_wrap *vm;
TypedData_Get_Struct(self, struct jsonnet_vm_wrap, &jsonnet_vm_type, vm);
jsonnet_debug_ast(vm->vm, RTEST(val));
return Qnil;
}
|
#evaluate(jsonnet, filename: "(jsonnet)", multi: false) ⇒ String
It is recommended to encode the source string in UTF-8 because Jsonnet expects it is ASCII-compatible, the result JSON string shall be UTF-8,16,32 according to RFC 7159 thus the only intersection between the requirements is UTF-8.
Evaluates Jsonnet source.
18 19 20 |
# File 'lib/jsonnet/vm.rb', line 18 def evaluate(jsonnet, filename: "(jsonnet)", multi: false) eval_snippet(jsonnet, filename, multi) end |
#evaluate_file(filename, encoding: Encoding.default_external, multi: false) ⇒ String
It is recommended to encode the source file in UTF-8 because Jsonnet expects it is ASCII-compatible, the result JSON string shall be UTF-8,16,32 according to RFC 7159 thus the only intersection between the requirements is UTF-8.
Evaluates Jsonnet file.
33 34 35 |
# File 'lib/jsonnet/vm.rb', line 33 def evaluate_file(filename, encoding: Encoding.default_external, multi: false) eval_file(filename, encoding, multi) end |
#ext_var(key, val) ⇒ Object
Binds an external variable to a value.
285 286 287 288 289 290 291 292 293 294 295 |
# File 'ext/jsonnet/jsonnet.c', line 285
static VALUE
vm_ext_var(VALUE self, VALUE key, VALUE val)
{
struct jsonnet_vm_wrap *vm;
enc_assert_asciicompat(StringValue(key));
enc_assert_asciicompat(StringValue(val));
TypedData_Get_Struct(self, struct jsonnet_vm_wrap, &jsonnet_vm_type, vm);
jsonnet_ext_var(vm->vm, StringValueCStr(key), StringValueCStr(val));
return Qnil;
}
|
#gc_growth_trigger=(val) ⇒ Object
315 316 317 318 319 320 321 322 |
# File 'ext/jsonnet/jsonnet.c', line 315
static VALUE
vm_set_gc_growth_trigger(VALUE self, VALUE val)
{
struct jsonnet_vm_wrap *vm;
TypedData_Get_Struct(self, struct jsonnet_vm_wrap, &jsonnet_vm_type, vm);
jsonnet_gc_growth_trigger(vm->vm, NUM2DBL(val));
return Qnil;
}
|
#gc_min_objects=(val) ⇒ Object
306 307 308 309 310 311 312 313 |
# File 'ext/jsonnet/jsonnet.c', line 306
static VALUE
vm_set_gc_min_objects(VALUE self, VALUE val)
{
struct jsonnet_vm_wrap *vm;
TypedData_Get_Struct(self, struct jsonnet_vm_wrap, &jsonnet_vm_type, vm);
jsonnet_gc_min_objects(vm->vm, NUM2UINT(val));
return Qnil;
}
|
#handle_import {|base, rel| ... } ⇒ Object
Lets the given block handle “import” expression of Jsonnet.
43 44 45 46 |
# File 'lib/jsonnet/vm.rb', line 43 def handle_import self.import_callback = Proc.new nil end |
#import_callback=(callback) ⇒ Object
Sets a custom way to resolve “import” expression.
269 270 271 272 273 274 275 276 277 278 |
# File 'ext/jsonnet/jsonnet.c', line 269
static VALUE
vm_set_import_callback(VALUE self, VALUE callback)
{
struct jsonnet_vm_wrap *vm;
TypedData_Get_Struct(self, struct jsonnet_vm_wrap, &jsonnet_vm_type, vm);
vm->callback = callback;
jsonnet_import_callback(vm->vm, import_callback_thunk, vm);
return callback;
}
|
#max_stack=(val) ⇒ Object
297 298 299 300 301 302 303 304 |
# File 'ext/jsonnet/jsonnet.c', line 297
static VALUE
vm_set_max_stack(VALUE self, VALUE val)
{
struct jsonnet_vm_wrap *vm;
TypedData_Get_Struct(self, struct jsonnet_vm_wrap, &jsonnet_vm_type, vm);
jsonnet_max_stack(vm->vm, NUM2UINT(val));
return Qnil;
}
|
#max_trace=(val) ⇒ Object
337 338 339 340 341 342 343 344 |
# File 'ext/jsonnet/jsonnet.c', line 337
static VALUE
vm_set_max_trace(VALUE self, VALUE val)
{
struct jsonnet_vm_wrap *vm;
TypedData_Get_Struct(self, struct jsonnet_vm_wrap, &jsonnet_vm_type, vm);
jsonnet_max_trace(vm->vm, NUM2UINT(val));
return Qnil;
}
|
#string_output=(val) ⇒ Object
Let #evalutae and #evaluate_file return a raw String instead of JSON-encoded string if val is true
328 329 330 331 332 333 334 335 |
# File 'ext/jsonnet/jsonnet.c', line 328
static VALUE
vm_set_string_output(VALUE self, VALUE val)
{
struct jsonnet_vm_wrap *vm;
TypedData_Get_Struct(self, struct jsonnet_vm_wrap, &jsonnet_vm_type, vm);
jsonnet_string_output(vm->vm, RTEST(val));
return Qnil;
}
|