Class: Chef::ChefFS::FileSystem::ChefServer::DataBagDir

Inherits:
RestListDir show all
Defined in:
lib/chef/chef_fs/file_system/chef_server/data_bag_dir.rb

Instance Attribute Summary

Attributes inherited from RestListDir

#api_path, #data_handler

Attributes inherited from BaseFSObject

#name, #parent, #path

Instance Method Summary collapse

Methods inherited from RestListDir

#can_have_child?, #children, #create_child, #environment, #org, #rest

Methods inherited from BaseFSDir

#can_have_child?, #empty?

Methods inherited from BaseFSObject

#can_have_child?, #chef_object, #child, #children, #compare_to, #create_child, #path_for_printing, #root, #write

Constructor Details

#initialize(name, parent, exists = nil) ⇒ DataBagDir

Returns a new instance of DataBagDir.



29
30
31
32
# File 'lib/chef/chef_fs/file_system/chef_server/data_bag_dir.rb', line 29

def initialize(name, parent, exists = nil)
  super(name, parent, nil, Chef::ChefFS::DataHandler::DataBagItemDataHandler.new)
  @exists = nil
end

Instance Method Details

#delete(recurse) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/chef/chef_fs/file_system/chef_server/data_bag_dir.rb', line 50

def delete(recurse)
  unless recurse
    raise NotFoundError.new(self) unless exists?

    raise MustDeleteRecursivelyError.new(self, "#{path_for_printing} must be deleted recursively")
  end
  begin
    rest.delete(api_path)
  rescue Timeout::Error => e
    raise Chef::ChefFS::FileSystem::OperationFailedError.new(:delete, self, e, "Timeout deleting: #{e}")
  rescue Net::HTTPClientException => e
    if e.response.code == "404"
      raise Chef::ChefFS::FileSystem::NotFoundError.new(self, e)
    else
      raise Chef::ChefFS::FileSystem::OperationFailedError.new(:delete, self, e, "HTTP error deleting: #{e}")
    end
  end
end

#dir?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/chef/chef_fs/file_system/chef_server/data_bag_dir.rb', line 34

def dir?
  exists?
end

#exists?Boolean

Returns:

  • (Boolean)


43
44
45
46
47
48
# File 'lib/chef/chef_fs/file_system/chef_server/data_bag_dir.rb', line 43

def exists?
  if @exists.nil?
    @exists = parent.children.any? { |child| child.name == name }
  end
  @exists
end

#make_child_entry(name, exists = nil) ⇒ Object



69
70
71
72
# File 'lib/chef/chef_fs/file_system/chef_server/data_bag_dir.rb', line 69

def make_child_entry(name, exists = nil)
  @children.find { |child| child.name == name } if @children
  DataBagEntry.new(name, self, exists)
end

#readObject



38
39
40
41
# File 'lib/chef/chef_fs/file_system/chef_server/data_bag_dir.rb', line 38

def read
  # This will only be called if dir? is false, which means exists? is false.
  raise Chef::ChefFS::FileSystem::NotFoundError.new(self)
end