Sha256: 058a6201dc1f6ec0e7e8ce920d97c16134b992c2547610aa99b6efa6b52a1570

Contents?: true

Size: 1.38 KB

Versions: 119

Compression:

Stored size: 1.38 KB

Contents

require 'chef/chef_fs/file_system/base_fs_dir'
require 'chef/chef_fs/file_system/nonexistent_fs_object'
require 'chef/chef_fs/file_system/memory_file'

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

        attr_reader :children

        def child(name)
          @children.select { |child| child.name == name }.first || Chef::ChefFS::FileSystem::NonexistentFSObject.new(name, self)
        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

Version data entries

119 entries across 119 versions & 1 rubygems

Version Path
chef-12.0.1 lib/chef/chef_fs/file_system/memory_dir.rb
chef-12.0.0-x86-mingw32 lib/chef/chef_fs/file_system/memory_dir.rb
chef-12.0.0 lib/chef/chef_fs/file_system/memory_dir.rb
chef-12.0.0.rc.0-x86-mingw32 lib/chef/chef_fs/file_system/memory_dir.rb
chef-12.0.0.rc.0 lib/chef/chef_fs/file_system/memory_dir.rb
chef-11.16.4-x86-mingw32 lib/chef/chef_fs/file_system/memory_dir.rb
chef-11.16.4 lib/chef/chef_fs/file_system/memory_dir.rb
chef-11.16.2-x86-mingw32 lib/chef/chef_fs/file_system/memory_dir.rb
chef-11.16.2 lib/chef/chef_fs/file_system/memory_dir.rb
chef-12.0.0.alpha.2-x86-mingw32 lib/chef/chef_fs/file_system/memory_dir.rb
chef-12.0.0.alpha.2 lib/chef/chef_fs/file_system/memory_dir.rb
chef-11.16.0-x86-mingw32 lib/chef/chef_fs/file_system/memory_dir.rb
chef-11.16.0 lib/chef/chef_fs/file_system/memory_dir.rb
chef-11.16.0.rc.0 lib/chef/chef_fs/file_system/memory_dir.rb
chef-12.0.0.alpha.1-x86-mingw32 lib/chef/chef_fs/file_system/memory_dir.rb
chef-12.0.0.alpha.1 lib/chef/chef_fs/file_system/memory_dir.rb
chef-11.14.6-x86-mingw32 lib/chef/chef_fs/file_system/memory_dir.rb
chef-11.14.6 lib/chef/chef_fs/file_system/memory_dir.rb
chef-11.14.2-x86-mingw32 lib/chef/chef_fs/file_system/memory_dir.rb
chef-11.14.2 lib/chef/chef_fs/file_system/memory_dir.rb