Class: Chef::ChefFS::FileSystem::CookbookDir
- Inherits:
-
BaseFSDir
show all
- Defined in:
- lib/chef/chef_fs/file_system/cookbook_dir.rb
Constant Summary
collapse
- COOKBOOK_SEGMENT_INFO =
{
:attributes => { :ruby_only => true },
:definitions => { :ruby_only => true },
:recipes => { :ruby_only => true },
:libraries => { :ruby_only => true },
:templates => { :recursive => true },
:files => { :recursive => true },
:resources => { :ruby_only => true, :recursive => true },
:providers => { :ruby_only => true, :recursive => true },
:root_files => { }
}
Instance Attribute Summary collapse
Attributes inherited from BaseFSObject
#name, #parent, #path
Instance Method Summary
collapse
#path_for_printing, #root
Constructor Details
#initialize(name, parent, versions = nil) ⇒ CookbookDir
Returns a new instance of CookbookDir.
30
31
32
33
|
# File 'lib/chef/chef_fs/file_system/cookbook_dir.rb', line 30
def initialize(name, parent, versions = nil)
super(name, parent)
@versions = versions
end
|
Instance Attribute Details
Returns the value of attribute versions.
35
36
37
|
# File 'lib/chef/chef_fs/file_system/cookbook_dir.rb', line 35
def versions
@versions
end
|
Instance Method Details
#add_child(child) ⇒ Object
49
50
51
|
# File 'lib/chef/chef_fs/file_system/cookbook_dir.rb', line 49
def add_child(child)
@children << child
end
|
53
54
55
|
# File 'lib/chef/chef_fs/file_system/cookbook_dir.rb', line 53
def api_path
"#{parent.api_path}/#{name}/_latest"
end
|
#can_have_child?(name, is_dir) ⇒ Boolean
69
70
71
72
73
74
75
76
|
# File 'lib/chef/chef_fs/file_system/cookbook_dir.rb', line 69
def can_have_child?(name, is_dir)
if is_dir
return name != 'root_files' &&
COOKBOOK_SEGMENT_INFO.keys.any? { |segment| segment.to_s == name }
end
true
end
|
#chef_object ⇒ Object
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
# File 'lib/chef/chef_fs/file_system/cookbook_dir.rb', line 143
def chef_object
return @chef_object if @chef_object
if @could_not_get_chef_object
raise Chef::ChefFS::FileSystem::NotFoundError.new(@could_not_get_chef_object), "#{path_for_printing} not found"
end
begin
old_retry_count = Chef::Config[:http_retry_count]
begin
Chef::Config[:http_retry_count] = 0
@chef_object ||= rest.get_rest(api_path)
ensure
Chef::Config[:http_retry_count] = old_retry_count
end
rescue Net::HTTPServerException
if $!.response.code == "404"
@could_not_get_chef_object = $!
raise Chef::ChefFS::FileSystem::NotFoundError.new(@could_not_get_chef_object), "#{path_for_printing} not found"
else
raise
end
rescue Net::HTTPFatalError
if $!.response.code == "500"
@could_not_get_chef_object = $!
raise Chef::ChefFS::FileSystem::NotFoundError.new(@could_not_get_chef_object), "#{path_for_printing} not found"
else
raise
end
end
end
|
#child(name) ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/chef/chef_fs/file_system/cookbook_dir.rb', line 57
def child(name)
begin
result = children.select { |child| child.name == name }.first
return result if result
rescue Chef::ChefFS::FileSystem::NotFoundError
end
return NonexistentFSObject.new(name, self)
end
|
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
# File 'lib/chef/chef_fs/file_system/cookbook_dir.rb', line 78
def children
if @children.nil?
@children = []
manifest = chef_object.manifest
COOKBOOK_SEGMENT_INFO.each do |segment, segment_info|
next unless manifest.has_key?(segment)
manifest[segment].each do |segment_file|
parts = segment_file[:path].split('/')
container = self
parts[0,parts.length-1].each do |part|
old_container = container
container = old_container.children.select { |child| part == child.name }.first
if !container
container = CookbookSubdir.new(part, old_container, segment_info[:ruby_only], segment_info[:recursive])
old_container.add_child(container)
end
end
container.add_child(CookbookFile.new(parts[parts.length-1], container, segment_file))
end
end
end
@children
end
|
#compare_to(other) ⇒ Object
124
125
126
127
128
129
130
131
132
133
|
# File 'lib/chef/chef_fs/file_system/cookbook_dir.rb', line 124
def compare_to(other)
if !other.dir?
return [ !exists?, nil, nil ]
end
are_same = true
Chef::ChefFS::CommandLine::diff_entries(self, other, nil, :name_only) do
are_same = false
end
[ are_same, nil, nil ]
end
|
#copy_from(other) ⇒ Object
135
136
137
|
# File 'lib/chef/chef_fs/file_system/cookbook_dir.rb', line 135
def copy_from(other)
parent.upload_cookbook_from(other)
end
|
#dir? ⇒ Boolean
107
108
109
|
# File 'lib/chef/chef_fs/file_system/cookbook_dir.rb', line 107
def dir?
exists?
end
|
#exists? ⇒ Boolean
116
117
118
119
120
121
122
|
# File 'lib/chef/chef_fs/file_system/cookbook_dir.rb', line 116
def exists?
if !@versions
child = parent.children.select { |child| child.name == name }.first
@versions = child.versions if child
end
!!@versions
end
|
139
140
141
|
# File 'lib/chef/chef_fs/file_system/cookbook_dir.rb', line 139
def rest
parent.rest
end
|