Class: Chef::ChefFS::FileSystem::RestListDir
- Inherits:
-
BaseFSDir
show all
- Defined in:
- lib/chef/chef_fs/file_system/rest_list_dir.rb
Instance Attribute Summary collapse
Attributes inherited from BaseFSObject
#name, #parent, #path
Instance Method Summary
collapse
Methods inherited from BaseFSDir
#dir?
#chef_object, #compare_to, #delete, #dir?, #exists?, #path_for_printing, #read, #root, #write
Constructor Details
#initialize(name, parent, api_path = nil, data_handler = nil) ⇒ RestListDir
Returns a new instance of RestListDir.
27
28
29
30
31
|
# File 'lib/chef/chef_fs/file_system/rest_list_dir.rb', line 27
def initialize(name, parent, api_path = nil, data_handler = nil)
super(name, parent)
@api_path = api_path || (parent.api_path == "" ? name : "#{parent.api_path}/#{name}")
@data_handler = data_handler
end
|
Instance Attribute Details
Returns the value of attribute api_path.
33
34
35
|
# File 'lib/chef/chef_fs/file_system/rest_list_dir.rb', line 33
def api_path
@api_path
end
|
#data_handler ⇒ Object
Returns the value of attribute data_handler.
34
35
36
|
# File 'lib/chef/chef_fs/file_system/rest_list_dir.rb', line 34
def data_handler
@data_handler
end
|
Instance Method Details
#_make_child_entry(name, exists = nil) ⇒ Object
109
110
111
|
# File 'lib/chef/chef_fs/file_system/rest_list_dir.rb', line 109
def _make_child_entry(name, exists = nil)
RestListEntry.new(name, self, exists)
end
|
#can_have_child?(name, is_dir) ⇒ Boolean
42
43
44
|
# File 'lib/chef/chef_fs/file_system/rest_list_dir.rb', line 42
def can_have_child?(name, is_dir)
name =~ /\.json$/ && !is_dir
end
|
#child(name) ⇒ Object
36
37
38
39
40
|
# File 'lib/chef/chef_fs/file_system/rest_list_dir.rb', line 36
def child(name)
result = @children.select { |child| child.name == name }.first if @children
result ||= can_have_child?(name, false) ?
_make_child_entry(name) : NonexistentFSObject.new(name, self)
end
|
#create_child(name, file_contents) ⇒ Object
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/chef/chef_fs/file_system/rest_list_dir.rb', line 62
def create_child(name, file_contents)
begin
object = Chef::JSONCompat.parse(file_contents)
rescue Chef::Exceptions::JSON::ParseError => e
raise Chef::ChefFS::FileSystem::OperationFailedError.new(:create_child, self, e), "Parse error reading JSON creating child '#{name}': #{e}"
end
result = _make_child_entry(name, true)
if data_handler
object = data_handler.normalize_for_post(object, result)
data_handler.verify_integrity(object, result) do |error|
raise Chef::ChefFS::FileSystem::OperationFailedError.new(:create_child, self), "Error creating '#{name}': #{error}"
end
end
begin
rest.post(api_path, object)
rescue Timeout::Error => e
raise Chef::ChefFS::FileSystem::OperationFailedError.new(:create_child, self, e), "Timeout creating '#{name}': #{e}"
rescue Net::HTTPServerException => e
if e.response.code == "404"
raise Chef::ChefFS::FileSystem::NotFoundError.new(self, e)
elsif $!.response.code == "409"
raise Chef::ChefFS::FileSystem::AlreadyExistsError.new(:create_child, self, e), "Failure creating '#{name}': #{path}/#{name} already exists"
else
raise Chef::ChefFS::FileSystem::OperationFailedError.new(:create_child, self, e), "Failure creating '#{name}': #{e.message}"
end
end
@children = nil
result
end
|
#environment ⇒ Object
101
102
103
|
# File 'lib/chef/chef_fs/file_system/rest_list_dir.rb', line 101
def environment
parent.environment
end
|
97
98
99
|
# File 'lib/chef/chef_fs/file_system/rest_list_dir.rb', line 97
def org
parent.org
end
|
105
106
107
|
# File 'lib/chef/chef_fs/file_system/rest_list_dir.rb', line 105
def rest
parent.rest
end
|