class Chef::ChefFS::FileSystemCache

Public Class Methods

new() click to toggle source
# File lib/chef/chef_fs/file_system_cache.rb, line 26
def initialize
  @cache = {}

  Chef::Client.when_run_starts do
    FileSystemCache.instance.reset!
  end
end

Public Instance Methods

children(path) click to toggle source
# File lib/chef/chef_fs/file_system_cache.rb, line 42
def children(path)
  @cache[path]["children"]
end
delete!(path) click to toggle source
# File lib/chef/chef_fs/file_system_cache.rb, line 52
def delete!(path)
  parent = _get_parent(path)
  Chef::Log.trace("Deleting parent #{parent} and #{path} from FileSystemCache")
  if @cache.key?(path)
    @cache.delete(path)
  end
  if !parent.nil? && @cache.key?(parent)
    @cache.delete(parent)
  end
end
exist?(path) click to toggle source
# File lib/chef/chef_fs/file_system_cache.rb, line 38
def exist?(path)
  @cache.key?(path)
end
fetch(path) click to toggle source
# File lib/chef/chef_fs/file_system_cache.rb, line 63
def fetch(path)
  if @cache.key?(path)
    @cache[path]
  else
    false
  end
end
reset!() click to toggle source
# File lib/chef/chef_fs/file_system_cache.rb, line 34
def reset!
  @cache = {}
end
set_children(path, val) click to toggle source
# File lib/chef/chef_fs/file_system_cache.rb, line 46
def set_children(path, val)
  @cache[path] ||= { "children" => [] }
  @cache[path]["children"] = val
  val
end

Private Instance Methods

_get_parent(path) click to toggle source
# File lib/chef/chef_fs/file_system_cache.rb, line 73
def _get_parent(path)
  parts = ChefFS::PathUtils.split(path)
  return nil if parts.nil? || parts.length < 2

  ChefFS::PathUtils.join(*parts[0..-2])
end