Class: ChefFS::FileSystem::CookbookDir
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 => { }
}
- VALID_VERSIONED_COOKBOOK_NAME =
/^([.a-zA-Z0-9_-]+)-(\d+\.\d+\.\d+)$/
Instance Attribute Summary collapse
Attributes inherited from BaseFSObject
#name, #parent, #path
Instance Method Summary
collapse
#create_child, #path_for_printing, #read, #root, #write
Constructor Details
#initialize(name, parent, options = {}) ⇒ CookbookDir
Returns a new instance of CookbookDir.
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/chef_fs/file_system/cookbook_dir.rb', line 29
def initialize(name, parent, options = {})
super(name, parent)
@exists = options[:exists]
if Chef::Config[:versioned_cookbooks]
if name =~ VALID_VERSIONED_COOKBOOK_NAME
@cookbook_name = $1
@version = $2
else
@exists = false
end
else
@cookbook_name = name
@version = root.cookbook_version end
end
|
Instance Attribute Details
#cookbook_name ⇒ Object
Returns the value of attribute cookbook_name.
47
48
49
|
# File 'lib/chef_fs/file_system/cookbook_dir.rb', line 47
def cookbook_name
@cookbook_name
end
|
#version ⇒ Object
Returns the value of attribute version.
47
48
49
|
# File 'lib/chef_fs/file_system/cookbook_dir.rb', line 47
def version
@version
end
|
Instance Method Details
#add_child(child) ⇒ Object
65
66
67
|
# File 'lib/chef_fs/file_system/cookbook_dir.rb', line 65
def add_child(child)
@children << child
end
|
#api_path ⇒ Object
69
70
71
|
# File 'lib/chef_fs/file_system/cookbook_dir.rb', line 69
def api_path
"#{parent.api_path}/#{cookbook_name}/#{version || "_latest"}"
end
|
#can_have_child?(name, is_dir) ⇒ Boolean
85
86
87
88
89
|
# File 'lib/chef_fs/file_system/cookbook_dir.rb', line 85
def can_have_child?(name, is_dir)
return name != 'root_files' && COOKBOOK_SEGMENT_INFO.keys.include?(name.to_sym) if is_dir
return true
end
|
#chef_object ⇒ Object
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
|
# File 'lib/chef_fs/file_system/cookbook_dir.rb', line 174
def chef_object
return @chef_object if @chef_object
if @could_not_get_chef_object
raise ChefFS::FileSystem::NotFoundError.new(self, @could_not_get_chef_object)
end
begin
old_retry_count = Chef::Config[:http_retry_count]
begin
Chef::Config[:http_retry_count] = 0
@chef_object ||= Chef::CookbookVersion.json_create(ChefFS::RawRequest.raw_json(rest, api_path))
ensure
Chef::Config[:http_retry_count] = old_retry_count
end
rescue Timeout::Error => e
raise ChefFS::FileSystem::OperationFailedError.new(:read, self, e), "Timeout reading: #{e}"
rescue Net::HTTPServerException => e
if e.response.code == "404"
@could_not_get_chef_object = e
raise ChefFS::FileSystem::NotFoundError.new(self, @could_not_get_chef_object)
else
raise ChefFS::FileSystem::OperationFailedError.new(:read, self, e), "HTTP error reading: #{e}"
end
rescue Net::HTTPFatalError => e
if e.response.code == "500"
@could_not_get_chef_object = e
raise ChefFS::FileSystem::NotFoundError.new(self, @could_not_get_chef_object)
else
raise ChefFS::FileSystem::OperationFailedError.new(:read, self, e), "HTTP error reading: #{e}"
end
end
end
|
#child(name) ⇒ Object
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/chef_fs/file_system/cookbook_dir.rb', line 73
def child(name)
begin
result = children.select { |child| child.name == name }.first
return result if result
rescue ChefFS::FileSystem::NotFoundError
end
return NonexistentFSObject.new(name, self)
end
|
#children ⇒ Object
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
# File 'lib/chef_fs/file_system/cookbook_dir.rb', line 91
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
@children = @children.sort_by { |c| c.name }
end
@children
end
|
#compare_to(other) ⇒ Object
153
154
155
156
157
158
159
160
161
162
163
164
|
# File 'lib/chef_fs/file_system/cookbook_dir.rb', line 153
def compare_to(other)
if !other.dir?
return [ !exists?, nil, nil ]
end
are_same = true
ChefFS::CommandLine::diff_entries(self, other, nil, :name_only).each do |type, old_entry, new_entry|
if [ :directory_to_file, :file_to_directory, :deleted, :added, :modified ].include?(type)
are_same = false
end
end
[ are_same, nil, nil ]
end
|
#copy_from(other, options = {}) ⇒ Object
166
167
168
|
# File 'lib/chef_fs/file_system/cookbook_dir.rb', line 166
def copy_from(other, options = {})
parent.upload_cookbook_from(other, options)
end
|
#delete(recurse) ⇒ Object
#dir? ⇒ Boolean
121
122
123
|
# File 'lib/chef_fs/file_system/cookbook_dir.rb', line 121
def dir?
exists?
end
|
#exists? ⇒ Boolean
In versioned cookbook mode, actually check if the version exists Probably want to cache this.
146
147
148
149
150
151
|
# File 'lib/chef_fs/file_system/cookbook_dir.rb', line 146
def exists?
if @exists.nil?
@exists = parent.children.any? { |child| child.name == name }
end
@exists
end
|
#rest ⇒ Object
170
171
172
|
# File 'lib/chef_fs/file_system/cookbook_dir.rb', line 170
def rest
parent.rest
end
|