Module: MarathonDeploy::YamlJson
- Defined in:
- lib/marathon_deploy/yaml_json.rb
Class Method Summary collapse
- .json2yaml(filename, process_macros = true) ⇒ Object
- .read_json(filename) ⇒ Object
- .read_json_w_macros(filename) ⇒ Object
- .yaml2json(filename, process_macros = true) ⇒ Object
Class Method Details
.json2yaml(filename, process_macros = true) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/marathon_deploy/yaml_json.rb', line 21 def self.json2yaml(filename, process_macros=true) if (process_macros) json = read_json_w_macros(filename) else json = read_json(filename) end yml = YAML::dump(json) end |
.read_json(filename) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/marathon_deploy/yaml_json.rb', line 30 def self.read_json(filename) file = File.open(filename,'r') data = file.read file.close return JSON.parse(data) end |
.read_json_w_macros(filename) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/marathon_deploy/yaml_json.rb', line 37 def self.read_json_w_macros(filename) begin data = Macro::process_macros(filename) rescue Error::UndefinedMacroError => e abort(e.) end return JSON.parse(data) end |
.yaml2json(filename, process_macros = true) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/marathon_deploy/yaml_json.rb', line 8 def self.yaml2json(filename, process_macros=true) if (process_macros) begin data = YAML::load(Macro::process_macros(filename)) rescue Error::UndefinedMacroError => e abort(e.) end else data = YAML::load_file(filename) end JSON.parse(JSON.dump(data)) end |