Class: Puppet::Pops::Lookup::EnvironmentContext Private
- Inherits:
-
Adaptable::Adapter
- Object
- Adaptable::Adapter
- Puppet::Pops::Lookup::EnvironmentContext
- Defined in:
- lib/puppet/pops/lookup/context.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
The EnvironmentContext is adapted to the current environment
Defined Under Namespace
Classes: FileData
Instance Attribute Summary collapse
- #environment_name ⇒ Object readonly private
Class Method Summary collapse
Instance Method Summary collapse
-
#cached_file_data(path) {|content| ... } ⇒ Object
private
Loads the contents of the file given by path.
-
#initialize(environment) ⇒ EnvironmentContext
constructor
private
A new instance of EnvironmentContext.
Methods inherited from Adaptable::Adapter
adapt, adapt_new, associate_adapter, clear, get, instance_var_name, self_attr_name, type_name
Constructor Details
#initialize(environment) ⇒ EnvironmentContext
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of EnvironmentContext.
32 33 34 35 |
# File 'lib/puppet/pops/lookup/context.rb', line 32 def initialize(environment) @environment_name = environment.name @file_data_cache = {} end |
Instance Attribute Details
#environment_name ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
26 27 28 |
# File 'lib/puppet/pops/lookup/context.rb', line 26 def environment_name @environment_name end |
Class Method Details
.create_adapter(environment) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
28 29 30 |
# File 'lib/puppet/pops/lookup/context.rb', line 28 def self.create_adapter(environment) new(environment) end |
Instance Method Details
#cached_file_data(path) {|content| ... } ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
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.
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/puppet/pops/lookup/context.rb', line 48 def cached_file_data(path) file_data = @file_data_cache[path] stat = Puppet::FileSystem.stat(path) unless file_data && file_data.valid?(stat) Puppet.debug { "File at '#{path}' was changed, reloading" } if file_data content = Puppet::FileSystem.read(path, :encoding => 'utf-8') file_data = FileData.new(path, stat.ino, stat.mtime, stat.size, block_given? ? yield(content) : content) @file_data_cache[path] = file_data end file_data.data end |