require 'chef/knife' require 'yaml' class Chef class Knife module Core class ObjectLoader def object_from_file(filename) case filename when /\.(js|json)$/ r = Yajl::Parser.parse(IO.read(filename)) # Chef::DataBagItem doesn't work well with the json_create method if @klass == Chef::DataBagItem r else @klass.json_create(r) end when /\.rb$/ r = klass.new r.from_file(filename) r when /\.yml$/ r = YAML.load_file(filename) puts "r: #{r}" @klass.json_create(r.to_json) else ui.fatal("File must end in .js, .json, .rb or .yml") exit 30 end end end end end end