Class: ChefFS::FileSystem::ChefRepositoryFileSystemCookbookDir
Instance Attribute Summary
#recursive, #ruby_only
#file_path
Attributes inherited from BaseFSObject
#name, #parent, #path
Class Method Summary
collapse
Instance Method Summary
collapse
#data_handler
#create_child, #delete, #dir?, #path_for_printing, #read, #write
Methods inherited from BaseFSDir
#child, #dir?
#child, #compare_to, #create_child, #delete, #dir?, #exists?, #path_for_printing, #read, #root, #write
Constructor Details
27
28
29
|
# File 'lib/chef_fs/file_system/chef_repository_file_system_cookbook_dir.rb', line 27
def initialize(name, parent, file_path = nil)
super(name, parent, file_path)
end
|
Class Method Details
.canonical_cookbook_name(entry_name) ⇒ Object
Exposed as a class method so that it can be used elsewhere
72
73
74
75
76
|
# File 'lib/chef_fs/file_system/chef_repository_file_system_cookbook_dir.rb', line 72
def self.canonical_cookbook_name(entry_name)
name_match = ChefFS::FileSystem::CookbookDir::VALID_VERSIONED_COOKBOOK_NAME.match(entry_name)
return nil if name_match.nil?
return name_match[1]
end
|
Instance Method Details
#can_have_child?(name, is_dir) ⇒ Boolean
62
63
64
65
66
67
68
69
|
# File 'lib/chef_fs/file_system/chef_repository_file_system_cookbook_dir.rb', line 62
def can_have_child?(name, is_dir)
if is_dir
return CookbookDir::COOKBOOK_SEGMENT_INFO.keys.include?(name.to_sym) && name != 'root_files'
end
super(name, is_dir)
end
|
#canonical_cookbook_name(entry_name) ⇒ Object
78
79
80
|
# File 'lib/chef_fs/file_system/chef_repository_file_system_cookbook_dir.rb', line 78
def canonical_cookbook_name(entry_name)
self.class.canonical_cookbook_name(entry_name)
end
|
#chef_object ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/chef_fs/file_system/chef_repository_file_system_cookbook_dir.rb', line 31
def chef_object
begin
loader = Chef::Cookbook::CookbookVersionLoader.new(file_path, parent.chefignore)
if Chef::Config[:versioned_cookbooks]
_canonical_name = canonical_cookbook_name(File.basename(file_path))
fail "When versioned_cookbooks mode is on, cookbook #{file_path} must match format <cookbook_name>-x.y.z" unless _canonical_name
loader.instance_variable_set(:@cookbook_name, _canonical_name)
end
loader.load_cookbooks
return loader.cookbook_version
rescue
Chef::Log.error("Could not read #{path_for_printing} into a Chef object: #{$!}")
end
nil
end
|
#children ⇒ Object
52
53
54
55
56
57
58
59
60
|
# File 'lib/chef_fs/file_system/chef_repository_file_system_cookbook_dir.rb', line 52
def children
Dir.entries(file_path).sort.
select { |child_name| can_have_child?(child_name, File.directory?(File.join(file_path, child_name))) }.
map do |child_name|
segment_info = CookbookDir::COOKBOOK_SEGMENT_INFO[child_name.to_sym] || {}
ChefRepositoryFileSystemCookbookEntry.new(child_name, self, nil, segment_info[:ruby_only], segment_info[:recursive])
end.
select { |entry| !(entry.dir? && entry.children.size == 0) }
end
|