Class: I18n::Tasks::Scanners::Files::CachingFileReader

Inherits:
FileReader
  • Object
show all
Defined in:
lib/i18n/tasks/scanners/files/caching_file_reader.rb

Overview

Note:

This class is thread-safe. All methods are cached.

Reads the files in ‘rb’ mode and UTF-8 encoding. Wraps a FileReader and caches the results.

Since:

  • 0.9.0

Instance Method Summary collapse

Constructor Details

#initializeCachingFileReader

Returns a new instance of CachingFileReader.

Since:

  • 0.9.0



13
14
15
16
# File 'lib/i18n/tasks/scanners/files/caching_file_reader.rb', line 13

def initialize
  super
  @cache = ::I18n::Tasks::Concurrent::Cache.new
end

Instance Method Details

#read_file(path) ⇒ String

Note:

This method is cached, it will only access the filesystem on the first invocation.

Return the contents of the file at the given path. The file is read in the ‘rb’ mode and UTF-8 encoding.

Parameters:

  • path (String)

    Path to the file, absolute or relative to the working directory.

Returns:

  • (String)

    file contents

Since:

  • 0.9.0



24
25
26
# File 'lib/i18n/tasks/scanners/files/caching_file_reader.rb', line 24

def read_file(path)
  @cache.fetch(File.expand_path(path)) { super }
end