Sha256: dcf82c3140a44da59aecedcbf0daeb67aca2e1bbf1a3459cbe4b163351bd2e95
Contents?: true
Size: 584 Bytes
Versions: 15
Compression:
Stored size: 584 Bytes
Contents
require "yaml" require "json" namespace :misc do desc "Convert a YAML file to JSON" task :yaml2json, [:path] do |_, arg| path = File.expand_path(arg[:path]) ext = case File.extname(path).downcase when ".yml" then ".yml" when ".yaml" then ".yaml" else "" end base_name = File.basename(path, ext) dir = File.dirname(path) out_file = File.join(dir, "#{base_name}.json") input = YAML.load_file(path) output = JSON.pretty_generate(input) File.open(out_file, "a") { |f| f.write(output) } end end
Version data entries
15 entries across 15 versions & 1 rubygems