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 26 def self.create_adapter(environment) 27 new(environment) 28 end
new(environment)
click to toggle source
# File lib/puppet/pops/lookup/context.rb 30 def initialize(environment) 31 @environment_name = environment.name 32 @file_data_cache = {} 33 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 46 def cached_file_data(path) 47 file_data = @file_data_cache[path] 48 stat = Puppet::FileSystem.stat(path) 49 unless file_data && file_data.valid?(stat) 50 Puppet.debug { "File at '#{path}' was changed, reloading" } if file_data 51 content = Puppet::FileSystem.read(path, :encoding => 'utf-8') 52 file_data = FileData.new(path, stat.ino, stat.mtime, stat.size, block_given? ? yield(content) : content) 53 @file_data_cache[path] = file_data 54 end 55 file_data.data 56 end