Class: Chef::ChefFS::FileSystem::ChefRepositoryFileSystemRootDir

Inherits:
BaseFSDir show all
Defined in:
lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb

Instance Attribute Summary collapse

Attributes inherited from BaseFSObject

#name, #parent, #path

Instance Method Summary collapse

Methods inherited from BaseFSDir

#child, #dir?

Methods inherited from BaseFSObject

#chef_object, #child, #compare_to, #delete, #dir?, #exists?, #path_for_printing, #read, #root, #write

Constructor Details

#initialize(child_paths) ⇒ ChefRepositoryFileSystemRootDir

Returns a new instance of ChefRepositoryFileSystemRootDir.



37
38
39
40
# File 'lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb', line 37

def initialize(child_paths)
  super("", nil)
  @child_paths = child_paths
end

Instance Attribute Details

#child_pathsObject (readonly)

Returns the value of attribute child_paths.



44
45
46
# File 'lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb', line 44

def child_paths
  @child_paths
end

#write_pretty_jsonObject

Returns the value of attribute write_pretty_json.



42
43
44
# File 'lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb', line 42

def write_pretty_json
  @write_pretty_json
end

Instance Method Details

#can_have_child?(name, is_dir) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb', line 50

def can_have_child?(name, is_dir)
  child_paths.has_key?(name) && is_dir
end

#childrenObject



46
47
48
# File 'lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb', line 46

def children
  @children ||= child_paths.keys.sort.map { |name| make_child_entry(name) }.select { |child| !child.nil? }
end

#create_child(name, file_contents = nil) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb', line 54

def create_child(name, file_contents = nil)
  child_paths[name].each do |path|
    begin
      Dir.mkdir(path)
    rescue Errno::EEXIST
    end
  end
  child = make_child_entry(name)
  @children = nil
  child
end

#fs_descriptionObject

Used to print out the filesystem



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb', line 71

def fs_description
  repo_path = File.dirname(child_paths['cookbooks'][0])
  result = "repository at #{repo_path}\n"
  if Chef::Config[:versioned_cookbooks]
    result << "  Multiple versions per cookbook\n"
  else
    result << "  One version per cookbook\n"
  end
  child_paths.each_pair do |name, paths|
    if paths.any? { |path| File.dirname(path) != repo_path }
      result << "  #{name} at #{paths.join(', ')}\n"
    end
  end
  result
end

#json_classObject



66
67
68
# File 'lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb', line 66

def json_class
  nil
end