Method: Chef::ChefFS::FilePattern#exact_child_name_under

Defined in:
lib/chef/chef_fs/file_pattern.rb

#exact_child_name_under(path) ⇒ Object

Returns the immediate child of a path that would be matched if this FilePattern was applied. If more than one child could match, this method returns nil.

Attributes

  • path - The path to look for an exact child name under.

Returns

The next directory in the pattern under the given path. If the directory part could match more than one child, it returns nil.

Examples

abc/def.exact_child_name_under('abc') == 'def'
abc/def/ghi.exact_child_name_under('abc') == 'def'
abc/*/ghi.exact_child_name_under('abc') == nil
abc/*/ghi.exact_child_name_under('abc/def') == 'ghi'
abc/**/ghi.exact_child_name_under('abc/def') == nil

This method assumes could_match_children?(path) is true.



115
116
117
118
119
120
121
# File 'lib/chef/chef_fs/file_pattern.rb', line 115

def exact_child_name_under(path)
  path = path[1, path.length - 1] if Chef::ChefFS::PathUtils.is_absolute?(path)
  dirs_in_path = Chef::ChefFS::PathUtils.split(path).length
  return nil if exact_parts.length <= dirs_in_path

  exact_parts[dirs_in_path]
end