Class: ThemeCheck::InMemoryStorage
- Defined in:
- lib/theme_check/in_memory_storage.rb
Instance Method Summary collapse
- #directories ⇒ Object
- #files ⇒ Object
-
#initialize(files = {}, root = "/dev/null") ⇒ InMemoryStorage
constructor
A new instance of InMemoryStorage.
- #path(relative_path) ⇒ Object
- #read(relative_path) ⇒ Object
- #relative_path(absolute_path) ⇒ Object
- #write(relative_path, content) ⇒ Object
Constructor Details
#initialize(files = {}, root = "/dev/null") ⇒ InMemoryStorage
Returns a new instance of InMemoryStorage.
9 10 11 12 |
# File 'lib/theme_check/in_memory_storage.rb', line 9 def initialize(files = {}, root = "/dev/null") @files = files @root = Pathname.new(root) end |
Instance Method Details
#directories ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/theme_check/in_memory_storage.rb', line 30 def directories @directories ||= @files .keys .flat_map { |relative_path| Pathname.new(relative_path).ascend.to_a } .map(&:to_s) .uniq end |
#files ⇒ Object
26 27 28 |
# File 'lib/theme_check/in_memory_storage.rb', line 26 def files @files.keys end |
#path(relative_path) ⇒ Object
14 15 16 |
# File 'lib/theme_check/in_memory_storage.rb', line 14 def path(relative_path) @root.join(relative_path) end |
#read(relative_path) ⇒ Object
18 19 20 |
# File 'lib/theme_check/in_memory_storage.rb', line 18 def read(relative_path) @files[relative_path] end |
#relative_path(absolute_path) ⇒ Object
38 39 40 |
# File 'lib/theme_check/in_memory_storage.rb', line 38 def relative_path(absolute_path) Pathname.new(absolute_path).relative_path_from(@root).to_s end |
#write(relative_path, content) ⇒ Object
22 23 24 |
# File 'lib/theme_check/in_memory_storage.rb', line 22 def write(relative_path, content) @files[relative_path] = content end |