Class: PlatformosCheck::InMemoryStorage

Inherits:
Storage
  • Object
show all
Defined in:
lib/platformos_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/platformos_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/platformos_check/in_memory_storage.rb', line 9

def root
  @root
end

Instance Method Details

#directoriesObject



50
51
52
53
54
55
56
# File 'lib/platformos_check/in_memory_storage.rb', line 50

def directories
  @directories ||= @files
                   .keys
                   .flat_map { |relative_path| Pathname.new(relative_path).ascend.to_a }
                   .map(&:to_s)
                   .uniq
end

#filesObject

TODO: Fix corrector def rename(old_path, new_path)

old_path += '/' if old_path[-1] != '/'
new_path += '/' if new_path[-1] != '/'
@files.transform_keys! { |k| k.sub(/\A#{old_path}/, new_path) }

reset_memoizers

end



46
47
48
# File 'lib/platformos_check/in_memory_storage.rb', line 46

def files
  @files.keys
end

#mkdir(relative_path) ⇒ Object



32
33
34
35
# File 'lib/platformos_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/platformos_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/platformos_check/in_memory_storage.rb', line 20

def read(relative_path)
  @files[relative_path]
end

#relative_path(absolute_path) ⇒ Object



58
59
60
# File 'lib/platformos_check/in_memory_storage.rb', line 58

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/platformos_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/platformos_check/in_memory_storage.rb', line 24

def write(relative_path, content)
  @files[relative_path] = content
end