Class: Chef::ChefFS::FileSystem::DataBagDir
Instance Attribute Summary
Attributes inherited from RestListDir
#api_path
Attributes inherited from BaseFSObject
#name, #parent, #path
Instance Method Summary
collapse
Methods inherited from RestListDir
#can_have_child?, #child, #children, #environment, #rest
Methods inherited from BaseFSDir
#can_have_child?, #child
#can_have_child?, #child, #compare_to, #path_for_printing, #root
Constructor Details
#initialize(name, parent, exists = nil) ⇒ DataBagDir
Returns a new instance of DataBagDir.
28
29
30
31
|
# File 'lib/chef/chef_fs/file_system/data_bag_dir.rb', line 28
def initialize(name, parent, exists = nil)
super(name, parent)
@exists = nil
end
|
Instance Method Details
#_make_child_entry(name, exists = nil) ⇒ Object
59
60
61
|
# File 'lib/chef/chef_fs/file_system/data_bag_dir.rb', line 59
def _make_child_entry(name, exists = nil)
DataBagItem.new(name, self, exists)
end
|
#create_child(name, file_contents) ⇒ Object
49
50
51
52
53
54
55
56
57
|
# File 'lib/chef/chef_fs/file_system/data_bag_dir.rb', line 49
def create_child(name, file_contents)
json = Chef::JSONCompat.from_json(file_contents).to_hash
id = name[0,name.length-5]
if json.include?('id') && json['id'] != id
raise "ID in #{path_for_printing}/#{name} must be '#{id}' (is '#{json['id']}')"
end
rest.post_rest(api_path, json)
_make_child_entry(name, true)
end
|
#dir? ⇒ Boolean
33
34
35
|
# File 'lib/chef/chef_fs/file_system/data_bag_dir.rb', line 33
def dir?
exists?
end
|
#exists? ⇒ Boolean
42
43
44
45
46
47
|
# File 'lib/chef/chef_fs/file_system/data_bag_dir.rb', line 42
def exists?
if @exists.nil?
@exists = parent.children.any? { |child| child.name == name }
end
@exists
end
|
37
38
39
40
|
# File 'lib/chef/chef_fs/file_system/data_bag_dir.rb', line 37
def read
raise Chef::ChefFS::FileSystem::NotFoundError, "#{path_for_printing} not found"
end
|