Method: ChefAPI::Resource::DataBagItem.from_file

Defined in:
lib/chef-api/resources/data_bag_item.rb

.from_file(path, bag = File.basename(File.dirname(path))) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/chef-api/resources/data_bag_item.rb', line 11

def from_file(path, bag = File.basename(File.dirname(path)))
  id, contents = Util.safe_read(path)
  data = JSON.parse(contents)
  data[:id] = id

  bag = bag.is_a?(Resource::DataBag) ? bag : Resource::DataBag.new(name: bag)

  new(data, { bag: bag.name }, bag)
end