Module: Puppet::Util::Autoload::FileCache

Included in:
Puppet::Util::Autoload
Defined in:
lib/vendor/puppet/util/autoload/file_cache.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.found_filesObject (readonly)

Returns the value of attribute found_files.



5
6
7
# File 'lib/vendor/puppet/util/autoload/file_cache.rb', line 5

def found_files
  @found_files
end

.missing_filesObject (readonly)

Returns the value of attribute missing_files.



5
6
7
# File 'lib/vendor/puppet/util/autoload/file_cache.rb', line 5

def missing_files
  @missing_files
end

Class Method Details

.clearObject

Only used for testing.



9
10
11
12
# File 'lib/vendor/puppet/util/autoload/file_cache.rb', line 9

def self.clear
  @found_files.clear
  @missing_files.clear
end

Instance Method Details

#directory_exist?(path) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/vendor/puppet/util/autoload/file_cache.rb', line 22

def directory_exist?(path)
  cache = cached_data?(path, :directory?)
  return cache unless cache.nil?

  protect(path) do
    stat = File.lstat(path)
    if stat.directory?
      found_file(path, stat)
      return true
    else
      missing_file(path)
      return false
    end
  end
end

#file_exist?(path) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
41
42
43
44
45
46
47
# File 'lib/vendor/puppet/util/autoload/file_cache.rb', line 38

def file_exist?(path)
  cache = cached_data?(path)
  return cache unless cache.nil?

  protect(path) do
    stat = File.lstat(path)
    found_file(path, stat)
    return true
  end
end

#found_file(path, stat) ⇒ Object



57
58
59
# File 'lib/vendor/puppet/util/autoload/file_cache.rb', line 57

def found_file(path, stat)
  found_files[path] = {:stat => stat, :time => Time.now}
end

#found_file?(path, type = nil) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
52
53
54
55
# File 'lib/vendor/puppet/util/autoload/file_cache.rb', line 49

def found_file?(path, type = nil)
  if data = found_files[path] and ! data_expired?(data[:time])
    return(type and ! data[:stat].send(type)) ? false : true
  else
    return false
  end
end

#found_filesObject



14
15
16
# File 'lib/vendor/puppet/util/autoload/file_cache.rb', line 14

def found_files
  Puppet::Util::Autoload::FileCache.found_files
end

#missing_file(path) ⇒ Object



65
66
67
# File 'lib/vendor/puppet/util/autoload/file_cache.rb', line 65

def missing_file(path)
  missing_files[path] = Time.now
end

#missing_file?(path) ⇒ Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/vendor/puppet/util/autoload/file_cache.rb', line 61

def missing_file?(path)
  !!(time = missing_files[path] and ! data_expired?(time))
end

#missing_filesObject



18
19
20
# File 'lib/vendor/puppet/util/autoload/file_cache.rb', line 18

def missing_files
  Puppet::Util::Autoload::FileCache.missing_files
end