Class: Chef::ChefFS::FileSystem::Repository::ChefRepositoryFileSystemRootDir
- Inherits:
-
BaseFSDir
- Object
- BaseFSObject
- BaseFSDir
- Chef::ChefFS::FileSystem::Repository::ChefRepositoryFileSystemRootDir
- Defined in:
- lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb
Overview
Represents the root of a local Chef repository, with directories for nodes, cookbooks, roles, etc. under it.
Constant Summary collapse
- CHILDREN =
%w{org.json invitations.json members.json}
Instance Attribute Summary collapse
-
#child_paths ⇒ Object
readonly
Returns the value of attribute child_paths.
-
#root_paths ⇒ Object
readonly
Returns the value of attribute root_paths.
-
#versioned_cookbooks ⇒ Object
readonly
Returns the value of attribute versioned_cookbooks.
-
#write_pretty_json ⇒ Object
Returns the value of attribute write_pretty_json.
Attributes inherited from BaseFSObject
Instance Method Summary collapse
- #can_have_child?(name, is_dir) ⇒ Boolean
- #children ⇒ Object
- #create_child(name, file_contents = nil) ⇒ Object
-
#fs_description ⇒ Object
Used to print out a human-readable file system description.
-
#initialize(child_paths, root_paths = [], chef_config = Chef::Config) ⇒ ChefRepositoryFileSystemRootDir
constructor
Create a new Chef Repository File System root.
- #json_class ⇒ Object
Methods inherited from BaseFSDir
Methods inherited from BaseFSObject
#chef_object, #child, #compare_to, #delete, #dir?, #exists?, #path_for_printing, #read, #root, #write
Constructor Details
#initialize(child_paths, root_paths = [], chef_config = Chef::Config) ⇒ ChefRepositoryFileSystemRootDir
Create a new Chef Repository File System root.
Parameters
- child_paths
-
A hash of child paths, e.g.:
"nodes" => [ '/var/nodes', '/home/jkeiser/nodes' ], "roles" => [ '/var/roles' ], ...
- root_paths
-
An array of paths representing the top level, where
org.json
,members.json
, andinvites.json
will be stored. - chef_config
-
a hash of options that looks suspiciously like the ones
-
stored in Chef::Config, containing at least these keys:
:versioned_cookbooks:: whether to include versions in cookbook names
65 66 67 68 69 70 |
# File 'lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb', line 65 def initialize(child_paths, root_paths = [], chef_config = Chef::Config) super("", nil) @child_paths = child_paths @root_paths = root_paths @versioned_cookbooks = chef_config[:versioned_cookbooks] end |
Instance Attribute Details
#child_paths ⇒ Object (readonly)
Returns the value of attribute child_paths.
75 76 77 |
# File 'lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb', line 75 def child_paths @child_paths end |
#root_paths ⇒ Object (readonly)
Returns the value of attribute root_paths.
74 75 76 |
# File 'lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb', line 74 def root_paths @root_paths end |
#versioned_cookbooks ⇒ Object (readonly)
Returns the value of attribute versioned_cookbooks.
76 77 78 |
# File 'lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb', line 76 def versioned_cookbooks @versioned_cookbooks end |
#write_pretty_json ⇒ Object
Returns the value of attribute write_pretty_json.
72 73 74 |
# File 'lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb', line 72 def write_pretty_json @write_pretty_json end |
Instance Method Details
#can_have_child?(name, is_dir) ⇒ Boolean
88 89 90 91 92 93 94 95 96 |
# File 'lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb', line 88 def can_have_child?(name, is_dir) if is_dir child_paths.has_key?(name) elsif root_dir CHILDREN.include?(name) else false end end |
#children ⇒ Object
80 81 82 83 84 85 86 |
# File 'lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb', line 80 def children @children ||= begin result = child_paths.keys.sort.map { |name| make_child_entry(name) } result += CHILDREN.map { |name| make_child_entry(name) } result.select { |c| c && c.exists? }.sort_by { |c| c.name } end end |
#create_child(name, file_contents = nil) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb', line 98 def create_child(name, file_contents = nil) if file_contents child = root_dir.create_child(name, file_contents) else child_paths[name].each do |path| begin Dir.mkdir(path) rescue Errno::EEXIST end end child = make_child_entry(name) end @children = nil child end |
#fs_description ⇒ Object
Used to print out a human-readable file system description
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb', line 119 def fs_description repo_paths = root_paths || [ File.dirname(child_paths["cookbooks"][0]) ] result = "repository at #{repo_paths.join(', ')}\n" if 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| !repo_paths.include?(File.dirname(path)) } result << " #{name} at #{paths.join(', ')}\n" end end result end |
#json_class ⇒ Object
114 115 116 |
# File 'lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb', line 114 def json_class nil end |