Class: Chef::ChefFS::FileSystem::DataBagsDir

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

Instance Attribute Summary

Attributes inherited from RestListDir

#api_path

Attributes inherited from BaseFSObject

#name, #parent, #path

Instance Method Summary collapse

Methods inherited from RestListDir

#_make_child_entry, #environment, #rest

Methods inherited from BaseFSDir

#dir?

Methods inherited from BaseFSObject

#compare_to, #dir?, #exists?, #path_for_printing, #root

Constructor Details

#initialize(parent) ⇒ DataBagsDir

Returns a new instance of DataBagsDir.



26
27
28
# File 'lib/chef/chef_fs/file_system/data_bags_dir.rb', line 26

def initialize(parent)
  super("data_bags", parent, "data")
end

Instance Method Details

#can_have_child?(name, is_dir) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/chef/chef_fs/file_system/data_bags_dir.rb', line 49

def can_have_child?(name, is_dir)
  is_dir
end

#child(name) ⇒ Object



30
31
32
33
# 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

#childrenObject



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/chef/chef_fs/file_system/data_bags_dir.rb', line 35

def children
  begin
    @children ||= rest.get_rest(api_path).keys.map do |entry|
      DataBagDir.new(entry, self, true)
    end
  rescue Net::HTTPServerException
    if $!.response.code == "404"
      raise Chef::ChefFS::FileSystem::NotFoundError.new($!), "#{path_for_printing} not found"
    else
      raise
    end
  end
end

#create_child(name, file_contents) ⇒ Object



53
54
55
56
57
58
59
60
61
62
# File 'lib/chef/chef_fs/file_system/data_bags_dir.rb', line 53

def create_child(name, file_contents)
  begin
    rest.post_rest(api_path, { 'name' => name })
  rescue Net::HTTPServerException
    if $!.response.code != "409"
      raise
    end
  end
  DataBagDir.new(name, self, true)
end