lib/knife/undev/monkey_patches/object_loader.rb in knife-undev-0.0.1 vs lib/knife/undev/monkey_patches/object_loader.rb in knife-undev-0.0.2

- old
+ new

@@ -1,37 +1,30 @@ -require 'chef/knife' +require 'chef/knife/core/object_loader' require 'yaml' -class Chef - class Knife - module Core - class ObjectLoader +class Chef::Knife::Core::ObjectLoader - def object_from_file(filename) - case filename - when /\.(js|json)$/ - r = Yajl::Parser.parse(IO.read(filename)) + 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 - + # 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) + @klass.json_create(r) + else + ui.fatal("File must end in .js, .json, .rb or .yml") + exit 30 end end + end