Sha256: 2000e8e7e7cd0ecdeca809ee2762be4b82102cf397348bd99d5e4bbdd37a0d4f

Contents?: true

Size: 644 Bytes

Versions: 13

Compression:

Stored size: 644 Bytes

Contents

require 'chef/knife/core/object_loader'
require 'yaml'

class Chef::Knife::Core::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)
      @klass.json_create(r)
    else
      ui.fatal("File must end in .js, .json, .rb or .yml")
      exit 30
    end
  end

end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
knife-undev-0.1.4 lib/knife/undev/monkey_patches/object_loader.rb
knife-undev-0.1.3 lib/knife/undev/monkey_patches/object_loader.rb
knife-undev-0.1.2 lib/knife/undev/monkey_patches/object_loader.rb
knife-undev-0.1.1 lib/knife/undev/monkey_patches/object_loader.rb
knife-undev-0.1.0 lib/knife/undev/monkey_patches/object_loader.rb
knife-undev-0.0.9 lib/knife/undev/monkey_patches/object_loader.rb
knife-undev-0.0.8 lib/knife/undev/monkey_patches/object_loader.rb
knife-undev-0.0.7 lib/knife/undev/monkey_patches/object_loader.rb
knife-undev-0.0.6 lib/knife/undev/monkey_patches/object_loader.rb
knife-undev-0.0.5 lib/knife/undev/monkey_patches/object_loader.rb
knife-undev-0.0.4 lib/knife/undev/monkey_patches/object_loader.rb
knife-undev-0.0.3 lib/knife/undev/monkey_patches/object_loader.rb
knife-undev-0.0.2 lib/knife/undev/monkey_patches/object_loader.rb