class I18n::Processes::Scanners::Files::CachingFileReader
Reads the files in 'rb' mode and UTF-8 encoding. Wraps a {FileReader} and caches the results.
@note This class is thread-safe. All methods are cached. @since 0.9.0
Public Class Methods
new()
click to toggle source
Calls superclass method
# File lib/i18n/processes/scanners/files/caching_file_reader.rb, line 11 def initialize super @mutex = Mutex.new @cache = {} end
Public Instance Methods
read_file(path)
click to toggle source
Return the contents of the file at the given path. The file is read in the 'rb' mode and UTF-8 encoding.
@param (see FileReader#read_file
) @return (see FileReader#read_file
) @note This method is cached, it will only access the filesystem on the first invocation.
Calls superclass method
# File lib/i18n/processes/scanners/files/caching_file_reader.rb, line 23 def read_file(path) absolute_path = File.expand_path(path) @cache[absolute_path] || @mutex.synchronize { @cache[absolute_path] ||= super } end