简体   繁体   English

在Rails上使用ruby在本地验证yaml文件?

[英]validate a yaml file locally with ruby on rails?

Is there a good way to validate a YAML locally ? 有没有一种在本地验证YAML的好方法? I have several YAML issues in production env on deploy, like 我在部署时的生产环境中有几个YAML问题,例如

https://gist.github.com/anonymous/78bed61832ff72ff3426

Not very informative, I would like to know the file this happens in. Is is possible to improve debugging yaml issues a bit more? 信息不是很丰富,我想知道发生这种情况的文件。是否可以进一步改善yaml调试问题?

Also im not sure why this happens only in production and not in development. 我也不确定为什么只在生产中而不是在开发中发生这种情况。

I ended up writing a rake task to do this: save as /lib/yaml.rake for example ( .rake ! not .rb) 我最终编写了一个rake任务来执行此操作:例如另存为/lib/yaml.rake(.rake!不是.rb)

namespace :yaml do

desc "Test YAML files"
task :check => :environment do
  require 'yaml'

  d = Dir["./**/*.yml"]
  d.each do |file|
    begin
      puts "checking : #{file}"
      f = YAML.load_file(file)
    rescue Exception
      puts "failed to read #{file}: #{$!}"
    end
  end
end
end

Well, from my experience tracking down bugs in YAML is not easy. 好吧,以我的经验来跟踪YAML中的错误并不容易。 Online tools like yamllint usually give similar error messages like the ones Psych provides. yamllint这样的在线工具通常会给出类似Psych提供的错误消息。

Only thing I could advise is: check diff from local/production YAML files and see what has changed. 我唯一能建议的是:检查本地/生产YAML文件中的diff,看看有什么变化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM