Class: PlatformosCheck::FileSystemStorage
- Defined in:
- lib/platformos_check/file_system_storage.rb
Instance Attribute Summary collapse
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
- #directories ⇒ Object
-
#files ⇒ Object
TODO: Fix corrector def rename(old_path, new_path) return unless file_exists?(old_path).
-
#initialize(root, ignored_patterns: []) ⇒ FileSystemStorage
constructor
A new instance of FileSystemStorage.
- #mkdir(relative_path) ⇒ Object
- #path(relative_path) ⇒ Object
- #read(relative_path) ⇒ Object
- #relative_path(absolute_path) ⇒ Object
- #remove(relative_path) ⇒ Object
- #write(relative_path, content) ⇒ Object
Methods inherited from Storage
Constructor Details
#initialize(root, ignored_patterns: []) ⇒ FileSystemStorage
Returns a new instance of FileSystemStorage.
9 10 11 12 13 |
# File 'lib/platformos_check/file_system_storage.rb', line 9 def initialize(root, ignored_patterns: []) @root = Pathname.new(root) @ignored_patterns = ignored_patterns @files = {} end |
Instance Attribute Details
#root ⇒ Object (readonly)
Returns the value of attribute root.
7 8 9 |
# File 'lib/platformos_check/file_system_storage.rb', line 7 def root @root end |
Instance Method Details
#directories ⇒ Object
63 64 65 66 67 |
# File 'lib/platformos_check/file_system_storage.rb', line 63 def directories @directories ||= glob('**/') .select { |f| File.directory?(f) } .map { |f| f.relative_path_from(@root).to_s } end |
#files ⇒ Object
TODO: Fix corrector def rename(old_path, new_path)
return unless file_exists?(old_path)
reset_memoizers
file(old_path).mv(new_path)
end
57 58 59 60 61 |
# File 'lib/platformos_check/file_system_storage.rb', line 57 def files @file_array ||= glob("**/*") .reject { |path| File.directory?(path) } .map { |path| path.relative_path_from(@root).to_s } end |
#mkdir(relative_path) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/platformos_check/file_system_storage.rb', line 41 def mkdir(relative_path) return if file_exists?(relative_path) reset_memoizers file(relative_path).mkpath end |
#path(relative_path) ⇒ Object
19 20 21 |
# File 'lib/platformos_check/file_system_storage.rb', line 19 def path(relative_path) @root.join(relative_path) end |
#read(relative_path) ⇒ Object
23 24 25 26 27 |
# File 'lib/platformos_check/file_system_storage.rb', line 23 def read(relative_path) file(relative_path).read(mode: 'rb', encoding: 'UTF-8') rescue Errno::ENOENT nil end |
#relative_path(absolute_path) ⇒ Object
15 16 17 |
# File 'lib/platformos_check/file_system_storage.rb', line 15 def relative_path(absolute_path) Pathname.new(absolute_path).relative_path_from(@root).to_s end |
#remove(relative_path) ⇒ Object
36 37 38 39 |
# File 'lib/platformos_check/file_system_storage.rb', line 36 def remove(relative_path) file(relative_path).delete reset_memoizers end |
#write(relative_path, content) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/platformos_check/file_system_storage.rb', line 29 def write(relative_path, content) reset_memoizers unless file_exists?(relative_path) file(relative_path).dirname.mkpath unless file(relative_path).dirname.directory? file(relative_path).write(content, mode: 'w+b', encoding: 'UTF-8') end |