Module: Soltius::Utils::Json2Hcl

Included in:
Hcl
Defined in:
lib/soltius/utils/hcl.rb

Overview

HCL Parser, using json2hcl binary (github.com/kvz/json2hcl)

Author:

Constant Summary collapse

PATH =
File.expand_path('../../../ext/json2hcl.rb', __dir__)
EXISTS =
File.exists?(PATH)

Instance Method Summary collapse

Instance Method Details

#file_to_json(file) ⇒ Object

Reads a HCL file and parses it into JSON

Parameters:

  • File

    path (absolute)

Returns:

  • JSON String



59
60
61
# File 'lib/soltius/utils/hcl.rb', line 59

def file_to_json(file)
  `#{json2hcl} -reverse < #{file}`
end

#json2hclObject

Returns the full path to binary json2hcl from ext/json2hcl.rb

Returns:

  • String



41
42
43
# File 'lib/soltius/utils/hcl.rb', line 41

def json2hcl
  File.read(PATH)
end

#to_json(str) ⇒ Object

Parses a HCL String into JSON

Parameters:

  • HCL

    String

Returns:

  • JSON String



50
51
52
# File 'lib/soltius/utils/hcl.rb', line 50

def to_json(str)
  `echo #{str} | #{json2hcl} -reverse`
end