Class: Chef::ChefFS::FileSystem::ChefRepositoryFileSystemRootDir
- Inherits:
-
BaseFSDir
- Object
- BaseFSObject
- BaseFSDir
- Chef::ChefFS::FileSystem::ChefRepositoryFileSystemRootDir
- Defined in:
- lib/chef/chef_fs/file_system/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(invitations.json members.json org.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
56 57 58 59 60 61 |
# File 'lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb', line 56 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.
66 67 68 |
# File 'lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb', line 66 def child_paths @child_paths end |
#root_paths ⇒ Object (readonly)
Returns the value of attribute root_paths.
65 66 67 |
# File 'lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb', line 65 def root_paths @root_paths end |
#versioned_cookbooks ⇒ Object (readonly)
Returns the value of attribute versioned_cookbooks.
67 68 69 |
# File 'lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb', line 67 def versioned_cookbooks @versioned_cookbooks end |
#write_pretty_json ⇒ Object
Returns the value of attribute write_pretty_json.
63 64 65 |
# File 'lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb', line 63 def write_pretty_json @write_pretty_json end |
Instance Method Details
#can_have_child?(name, is_dir) ⇒ Boolean
79 80 81 82 83 84 85 86 87 |
# File 'lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb', line 79 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
71 72 73 74 75 76 77 |
# File 'lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb', line 71 def children @children ||= begin result = child_paths.keys.sort.map { |name| make_child_entry(name) }.select { |child| !child.nil? } result += root_dir.children.select { |c| CHILDREN.include?(c.name) } if root_dir result.sort_by { |c| c.name } end end |
#create_child(name, file_contents = nil) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb', line 89 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
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb', line 110 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
105 106 107 |
# File 'lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb', line 105 def json_class nil end |