class Chef::ChefFS::FileSystem::DataBagsDir

Public Class Methods

new(parent) click to toggle source
Calls superclass method
# File lib/chef/chef_fs/file_system/data_bags_dir.rb, line 26
def initialize(parent)
  super("data_bags", parent, "data")
end

Public Instance Methods

can_have_child?(name, is_dir) click to toggle source
# File lib/chef/chef_fs/file_system/data_bags_dir.rb, line 51
def can_have_child?(name, is_dir)
  is_dir
end
child(name) click to toggle source
# File lib/chef/chef_fs/file_system/data_bags_dir.rb, line 30
def child(name)
  result = @children.select { |child| child.name == name }.first if @children
  result || DataBagDir.new(name, self)
end
children() click to toggle source
# File lib/chef/chef_fs/file_system/data_bags_dir.rb, line 35
def children
  begin
    @children ||= root.get_json(api_path).keys.sort.map do |entry|
      DataBagDir.new(entry, self, true)
    end
  rescue Timeout::Error => e
    raise Chef::ChefFS::FileSystem::OperationFailedError.new(:children, self, e), "Timeout getting children: #{e}"
  rescue Net::HTTPServerException => e
    if e.response.code == "404"
      raise Chef::ChefFS::FileSystem::NotFoundError.new(self, e)
    else
      raise Chef::ChefFS::FileSystem::OperationFailedError.new(:children, self, e), "HTTP error getting children: #{e}"
    end
  end
end
create_child(name, file_contents) click to toggle source
# File lib/chef/chef_fs/file_system/data_bags_dir.rb, line 55
def create_child(name, file_contents)
  begin
    rest.post(api_path, { 'name' => name })
  rescue Timeout::Error => e
    raise Chef::ChefFS::FileSystem::OperationFailedError.new(:create_child, self, e), "Timeout creating child '#{name}': #{e}"
  rescue Net::HTTPServerException => e
    if e.response.code == "409"
      raise Chef::ChefFS::FileSystem::AlreadyExistsError.new(:create_child, self, e), "Cannot create #{name} under #{path}: already exists"
    else
      raise Chef::ChefFS::FileSystem::OperationFailedError.new(:create_child, self, e), "HTTP error creating child '#{name}': #{e}"
    end
  end
  @children = nil
  DataBagDir.new(name, self, true)
end