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

Version Path
eddy-0.10.0 tasks/misc/yaml2json.rake
eddy-0.9.2 tasks/misc/yaml2json.rake
eddy-0.9.1 tasks/misc/yaml2json.rake
eddy-0.9.0 tasks/misc/yaml2json.rake
eddy-0.8.4 tasks/misc/yaml2json.rake
eddy-0.8.3 tasks/misc/yaml2json.rake
eddy-0.8.2 tasks/misc/yaml2json.rake
eddy-0.8.1 tasks/misc/yaml2json.rake
eddy-0.8.0 tasks/misc/yaml2json.rake
eddy-0.7.0 tasks/misc/yaml2json.rake
eddy-0.6.0 tasks/misc/yaml2json.rake
eddy-0.5.1 tasks/misc/yaml2json.rake
eddy-0.5.0 tasks/misc/yaml2json.rake
eddy-0.4.0 tasks/misc/yaml2json.rake
eddy-0.3.0 tasks/misc/yaml2json.rake