Class: ThemeCheck::InMemoryStorage

Inherits:
Storage
  • Object
show all
Defined in:
lib/theme_check/in_memory_storage.rb

Direct Known Subclasses

VersionedInMemoryStorage

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Storage

#versioned?

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 # Hash<String, String>
  @root = Pathname.new(root)
end

Instance Attribute Details

#rootObject (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

#directoriesObject



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

#filesObject



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