Class: Chef::ChefFS::FileSystem::MultiplexedDir

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

Instance Attribute Summary collapse

Attributes inherited from BaseFSObject

#name, #parent, #path

Instance Method Summary collapse

Methods inherited from BaseFSDir

#dir?, #empty?

Methods inherited from BaseFSObject

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

Constructor Details

#initialize(*multiplexed_dirs) ⇒ MultiplexedDir

Returns a new instance of MultiplexedDir.



8
9
10
11
# File 'lib/chef/chef_fs/file_system/multiplexed_dir.rb', line 8

def initialize(*multiplexed_dirs)
  @multiplexed_dirs = multiplexed_dirs.flatten
  super(@multiplexed_dirs[0].name, @multiplexed_dirs[0].parent)
end

Instance Attribute Details

#multiplexed_dirsObject (readonly)

Returns the value of attribute multiplexed_dirs.



13
14
15
# File 'lib/chef/chef_fs/file_system/multiplexed_dir.rb', line 13

def multiplexed_dirs
  @multiplexed_dirs
end

Instance Method Details

#can_have_child?(name, is_dir) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/chef/chef_fs/file_system/multiplexed_dir.rb', line 53

def can_have_child?(name, is_dir)
  write_dir.can_have_child?(name, is_dir)
end

#childrenObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/chef/chef_fs/file_system/multiplexed_dir.rb', line 19

def children
  begin
    result = []
    seen = {}
    # If multiple things have the same name, the first one wins.
    multiplexed_dirs.each do |dir|
      dir.children.each do |child|
        if seen[child.name]
          Chef::Log.warn("Child with name '#{child.name}' found in multiple directories: #{seen[child.name].path_for_printing} and #{child.path_for_printing}") unless seen[child.name].path_for_printing == child.path_for_printing
        else
          result << child
          seen[child.name] = child
        end
      end
    end
    result
  end
end

#create_child(name, file_contents = nil) ⇒ Object



57
58
59
60
# File 'lib/chef/chef_fs/file_system/multiplexed_dir.rb', line 57

def create_child(name, file_contents = nil)
  @children = nil
  write_dir.create_child(name, file_contents)
end

#make_child_entry(name) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/chef/chef_fs/file_system/multiplexed_dir.rb', line 38

def make_child_entry(name)
  result = nil
  multiplexed_dirs.each do |dir|
    child_entry = dir.child(name)
    if child_entry.exists?
      if result
        Chef::Log.debug("Child with name '#{child_entry.name}' found in multiple directories: #{result.parent.path_for_printing} and #{child_entry.parent.path_for_printing}")
      else
        result = child_entry
      end
    end
  end
  result
end

#write_dirObject



15
16
17
# File 'lib/chef/chef_fs/file_system/multiplexed_dir.rb', line 15

def write_dir
  multiplexed_dirs[0]
end