Class: Chef::ChefFS::FileSystem::ChefRepositoryFileSystemEntry
- Inherits:
-
FileSystemEntry
- Object
- BaseFSObject
- BaseFSDir
- FileSystemEntry
- Chef::ChefFS::FileSystem::ChefRepositoryFileSystemEntry
- Defined in:
- lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb
Overview
ChefRepositoryFileSystemEntry works just like FileSystemEntry, except it pretends files in /cookbooks/chefignore don’t exist and it can inflate Chef objects
Direct Known Subclasses
Instance Attribute Summary collapse
-
#chefignore ⇒ Object
readonly
Returns the value of attribute chefignore.
Attributes inherited from FileSystemEntry
Attributes inherited from BaseFSObject
Instance Method Summary collapse
- #chef_object ⇒ Object
- #children ⇒ Object
- #ignore_empty_directories? ⇒ Boolean
-
#initialize(name, parent, file_path = nil) ⇒ ChefRepositoryFileSystemEntry
constructor
A new instance of ChefRepositoryFileSystemEntry.
Methods inherited from FileSystemEntry
#create_child, #delete, #dir?, #path_for_printing, #read, #write
Methods inherited from BaseFSDir
#can_have_child?, #child, #dir?
Methods inherited from BaseFSObject
#can_have_child?, #child, #compare_to, #dir?, #exists?, #path_for_printing, #root
Constructor Details
#initialize(name, parent, file_path = nil) ⇒ ChefRepositoryFileSystemEntry
Returns a new instance of ChefRepositoryFileSystemEntry.
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb', line 35 def initialize(name, parent, file_path = nil) super(name, parent, file_path) # Load /cookbooks/chefignore if name == "cookbooks" && path == "/cookbooks" # We check name first because it's a faster fail than path @chefignore = Chef::Cookbook::Chefignore.new(self.file_path) # If we are a cookbook or a cookbook subdirectory, empty directories # underneath us are ignored (since they cannot be uploaded) elsif parent && parent.name === "cookbooks" && parent.path == "/cookbooks" @ignore_empty_directories = true elsif parent && parent.ignore_empty_directories? @ignore_empty_directories = true end end |
Instance Attribute Details
#chefignore ⇒ Object (readonly)
Returns the value of attribute chefignore.
49 50 51 |
# File 'lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb', line 49 def chefignore @chefignore end |
Instance Method Details
#chef_object ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb', line 55 def chef_object begin if parent.path == "/cookbooks" loader = Chef::Cookbook::CookbookVersionLoader.new(file_path, parent.chefignore) loader.load_cookbooks return loader.cookbook_version end # Otherwise the information to inflate the object, is in the file (json_class). return Chef::JSONCompat.from_json(read) rescue Chef::Log.error("Could not read #{path_for_printing} into a Chef object: #{$!}") end nil end |
#children ⇒ Object
71 72 73 74 |
# File 'lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb', line 71 def children @children ||= Dir.entries(file_path).select { |entry| entry != '.' && entry != '..' && !ignored?(entry) }. map { |entry| ChefRepositoryFileSystemEntry.new(entry, self) } end |
#ignore_empty_directories? ⇒ Boolean
51 52 53 |
# File 'lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb', line 51 def ignore_empty_directories? @ignore_empty_directories end |