class Puppet::Pops::Lookup::EnvironmentContext
The EnvironmentContext is adapted to the current environment
Attributes
environment_name[R]
Public Class Methods
create_adapter(environment)
click to toggle source
# File lib/puppet/pops/lookup/context.rb 27 def self.create_adapter(environment) 28 new(environment) 29 end
new(environment)
click to toggle source
# File lib/puppet/pops/lookup/context.rb 31 def initialize(environment) 32 @environment_name = environment.name 33 @file_data_cache = {} 34 end
Public Instance Methods
cached_file_data(path) { |content| ... }
click to toggle source
Loads the contents of the file given by path. The content is then yielded to the provided block in case a block is given, and the returned value from that block is cached and returned by this method. If no block is given, the content is stored instead.
The cache is retained as long as the inode, mtime, and size of the file remains unchanged.
@param path [String] path to the file to be read @yieldparam content [String] the content that was read from the file @yieldreturn [Object] some result based on the content @return [Object] the content, or if a block was given, the return value of the block
# File lib/puppet/pops/lookup/context.rb 47 def cached_file_data(path) 48 file_data = @file_data_cache[path] 49 stat = Puppet::FileSystem.stat(path) 50 unless file_data && file_data.valid?(stat) 51 Puppet.debug { "File at '#{path}' was changed, reloading" } if file_data 52 content = Puppet::FileSystem.read(path, :encoding => 'utf-8') 53 file_data = FileData.new(path, stat.ino, stat.mtime, stat.size, block_given? ? yield(content) : content) 54 @file_data_cache[path] = file_data 55 end 56 file_data.data 57 end