Class Hiera::Filecache
In: lib/hiera/filecache.rb
Parent: Object

Methods

new   read   read_file  

Public Class methods

Public Instance methods

Reads a file, optionally parse it in some way check the output type and set a default

Simply invoking it this way will return the file contents

   data = read("/some/file")

But as most cases of file reading in hiera involves some kind of parsing through a serializer there‘s some help for those cases:

   data = read("/some/file", Hash, {}) do |data|
      JSON.parse(data)
   end

In this case it will read the file, parse it using JSON then check that the end result is a Hash, if it‘s not a hash or if reading/parsing fails it will return {} instead

Prior to calling this method you should be sure the file exist

Read a file when it changes. If a file is re-read and has not changed since the last time then the last, processed, contents will be returned.

The processed data can also be checked against an expected type. If the type does not match a TypeError is raised.

No error handling is done inside this method. Any failed reads or errors in processing will be propagated to the caller

[Validate]