Class: Mull::FileUtil
- Inherits:
-
Object
- Object
- Mull::FileUtil
- Defined in:
- lib/mull/file_util.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
Returns the value of attribute file.
-
#file_utils ⇒ Object
Returns the value of attribute file_utils.
-
#path_prefix ⇒ Object
Returns the value of attribute path_prefix.
Instance Method Summary collapse
-
#initialize(path_prefix:, file:, file_utils:) ⇒ FileUtil
constructor
A new instance of FileUtil.
- #read_file(path:) ⇒ Object
- #write_file(path:, content:) ⇒ Object
Constructor Details
#initialize(path_prefix:, file:, file_utils:) ⇒ FileUtil
Returns a new instance of FileUtil.
14 15 16 17 18 |
# File 'lib/mull/file_util.rb', line 14 def initialize(path_prefix:, file:, file_utils:) self.path_prefix = path_prefix || '.' self.file = file self.file_utils = file_utils end |
Instance Attribute Details
#file ⇒ Object
Returns the value of attribute file.
9 10 11 |
# File 'lib/mull/file_util.rb', line 9 def file @file end |
#file_utils ⇒ Object
Returns the value of attribute file_utils.
9 10 11 |
# File 'lib/mull/file_util.rb', line 9 def file_utils @file_utils end |
#path_prefix ⇒ Object
Returns the value of attribute path_prefix.
9 10 11 |
# File 'lib/mull/file_util.rb', line 9 def path_prefix @path_prefix end |
Instance Method Details
#read_file(path:) ⇒ Object
20 21 22 23 24 |
# File 'lib/mull/file_util.rb', line 20 def read_file(path:) return nil unless path path = file.join(path_prefix, path) file.read(path) end |
#write_file(path:, content:) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/mull/file_util.rb', line 26 def write_file(path:, content:) path = file.join(path_prefix, path) dir = file.dirname(path) unless file.exists?(dir) file_utils.mkpath(dir) end file.open(path, 'w+') { |f| f.write content } end |