Class: Ace::Support::Models::Atoms::FileReader

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/support/models/atoms/file_reader.rb

Overview

Reads files from the cache

Class Method Summary collapse

Class Method Details

.exist?(path) ⇒ Boolean

Check if file exists

Parameters:

  • path (String)

    File path

Returns:

  • (Boolean)

    true if file exists



26
27
28
# File 'lib/ace/support/models/atoms/file_reader.rb', line 26

def exist?(path)
  File.exist?(path)
end

.mtime(path) ⇒ Time?

Get file modification time

Parameters:

  • path (String)

    File path

Returns:

  • (Time, nil)

    Modification time or nil



33
34
35
36
37
# File 'lib/ace/support/models/atoms/file_reader.rb', line 33

def mtime(path)
  return nil unless File.exist?(path)

  File.mtime(path)
end

.read(path) ⇒ String?

Read file contents

Parameters:

  • path (String)

    File path

Returns:

  • (String, nil)

    File contents or nil if not found



13
14
15
16
17
18
19
20
21
# File 'lib/ace/support/models/atoms/file_reader.rb', line 13

def read(path)
  return nil unless File.exist?(path)

  File.read(path)
rescue Errno::EACCES => e
  raise CacheError, "Permission denied reading #{path}: #{e.message}"
rescue Errno::ENOENT
  nil
end