Sha256: 9d188617075e77a8680c9a8ba314523adfe16f8cdfefc1c68dd24012f168d7e7

Contents?: true

Size: 1.38 KB

Versions: 3

Compression:

Stored size: 1.38 KB

Contents

require_relative "../base_fs_dir"
require_relative "memory_file"

class Chef
  module ChefFS
    module FileSystem
      module Memory
        class MemoryDir < Chef::ChefFS::FileSystem::BaseFSDir
          def initialize(name, parent)
            super(name, parent)
            @children = []
          end

          attr_reader :children

          def make_child_entry(name)
            @children.find { |child| child.name == name }
          end

          def add_child(child)
            @children.push(child)
          end

          def can_have_child?(name, is_dir)
            root.cannot_be_in_regex ? (name !~ root.cannot_be_in_regex) : true
          end

          def add_file(path, value)
            path_parts = path.split("/")
            dir = add_dir(path_parts[0..-2].join("/"))
            file = MemoryFile.new(path_parts[-1], dir, value)
            dir.add_child(file)
            file
          end

          def add_dir(path)
            path_parts = path.split("/")
            dir = self
            path_parts.each do |path_part|
              subdir = dir.child(path_part)
              if !subdir.exists?
                subdir = MemoryDir.new(path_part, dir)
                dir.add_child(subdir)
              end
              dir = subdir
            end
            dir
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
chef-15.0.300-universal-mingw32 lib/chef/chef_fs/file_system/memory/memory_dir.rb
chef-15.0.298-universal-mingw32 lib/chef/chef_fs/file_system/memory/memory_dir.rb
chef-15.0.293-universal-mingw32 lib/chef/chef_fs/file_system/memory/memory_dir.rb