Class: Ace::Support::Models::Atoms::FileWriter
- Inherits:
-
Object
- Object
- Ace::Support::Models::Atoms::FileWriter
- Defined in:
- lib/ace/support/models/atoms/file_writer.rb
Overview
Writes files to the cache
Class Method Summary collapse
-
.delete(path) ⇒ Boolean
Delete file.
-
.ensure_directory(dir) ⇒ Boolean
Ensure directory exists.
-
.rename(from, to) ⇒ Boolean
Rename/move file.
-
.write(path, content) ⇒ Boolean
Write content to file.
Class Method Details
.delete(path) ⇒ Boolean
Delete file
40 41 42 43 44 45 |
# File 'lib/ace/support/models/atoms/file_writer.rb', line 40 def delete(path) File.delete(path) if File.exist?(path) true rescue Errno::EACCES => e raise CacheError, "Permission denied deleting #{path}: #{e.}" end |
.ensure_directory(dir) ⇒ Boolean
Ensure directory exists
30 31 32 33 34 35 |
# File 'lib/ace/support/models/atoms/file_writer.rb', line 30 def ensure_directory(dir) FileUtils.mkdir_p(dir) unless Dir.exist?(dir) true rescue Errno::EACCES => e raise CacheError, "Permission denied creating directory #{dir}: #{e.}" end |
.rename(from, to) ⇒ Boolean
Rename/move file
51 52 53 54 55 56 57 |
# File 'lib/ace/support/models/atoms/file_writer.rb', line 51 def rename(from, to) ensure_directory(File.dirname(to)) File.rename(from, to) true rescue Errno::EACCES => e raise CacheError, "Permission denied moving file: #{e.}" end |
.write(path, content) ⇒ Boolean
Write content to file
17 18 19 20 21 22 23 24 25 |
# File 'lib/ace/support/models/atoms/file_writer.rb', line 17 def write(path, content) ensure_directory(File.dirname(path)) File.write(path, content) true rescue Errno::EACCES => e raise CacheError, "Permission denied writing #{path}: #{e.}" rescue Errno::ENOSPC => e raise CacheError, "No space left writing #{path}: #{e.}" end |