Class: ThemeCheck::InMemoryStorage
- Defined in:
- lib/theme_check/in_memory_storage.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
- #directories ⇒ Object
- #files ⇒ Object
-
#initialize(files = {}, root = "/dev/null") ⇒ InMemoryStorage
constructor
A new instance of InMemoryStorage.
- #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(files = {}, root = "/dev/null") ⇒ InMemoryStorage
Returns a new instance of InMemoryStorage.
11 12 13 14 |
# File 'lib/theme_check/in_memory_storage.rb', line 11 def initialize(files = {}, root = "/dev/null") @files = files @root = Pathname.new(root) end |
Instance Attribute Details
#root ⇒ Object (readonly)
Returns the value of attribute root.
9 10 11 |
# File 'lib/theme_check/in_memory_storage.rb', line 9 def root @root end |
Instance Method Details
#directories ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/theme_check/in_memory_storage.rb', line 41 def directories @directories ||= @files .keys .flat_map { |relative_path| Pathname.new(relative_path).ascend.to_a } .map(&:to_s) .uniq end |
#files ⇒ Object
37 38 39 |
# File 'lib/theme_check/in_memory_storage.rb', line 37 def files @files.keys end |
#mkdir(relative_path) ⇒ Object
32 33 34 35 |
# File 'lib/theme_check/in_memory_storage.rb', line 32 def mkdir(relative_path) @files[relative_path] = nil reset_memoizers end |
#path(relative_path) ⇒ Object
16 17 18 |
# File 'lib/theme_check/in_memory_storage.rb', line 16 def path(relative_path) @root.join(relative_path) end |
#read(relative_path) ⇒ Object
20 21 22 |
# File 'lib/theme_check/in_memory_storage.rb', line 20 def read(relative_path) @files[relative_path] end |
#relative_path(absolute_path) ⇒ Object
49 50 51 |
# File 'lib/theme_check/in_memory_storage.rb', line 49 def relative_path(absolute_path) Pathname.new(absolute_path).relative_path_from(@root).to_s end |
#remove(relative_path) ⇒ Object
28 29 30 |
# File 'lib/theme_check/in_memory_storage.rb', line 28 def remove(relative_path) @files.delete(relative_path) end |
#write(relative_path, content) ⇒ Object
24 25 26 |
# File 'lib/theme_check/in_memory_storage.rb', line 24 def write(relative_path, content) @files[relative_path] = content end |