Sha256: e43d9e7b529d36c87b0299dc0f6c7de7d580c56b26f047e1dff7468f3720c0f6

Contents?: true

Size: 1.18 KB

Versions: 11

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true

# An in-memory storage is not written to disk. The reasons why you'd
# want to do that are your own. The idea is to not write to disk
# something that doesn't need to be there. If you have your platformos_app
# as a big hash already, leave it like that and save yourself some IO.
module PlatformosCheck
  class InMemoryStorage < Storage
    attr_reader :root

    def initialize(files = {}, root = "/dev/null")
      @files = files # Hash<String, String>
      @root = Pathname.new(root)
    end

    def path(relative_path)
      @root.join(relative_path)
    end

    def read(relative_path)
      @files[relative_path]
    end

    def write(relative_path, content)
      @platformos_app&.update([relative_path])
      @files[relative_path] = content
    end

    def remove(relative_path)
      @platformos_app&.update([relative_path], remove: true)
      @files.delete(relative_path)
    end

    def mkdir(relative_path)
      @files[relative_path] = nil
    end

    def files
      @files.keys
    end

    def files_with_content
      @files
    end

    def relative_path(absolute_path)
      Pathname.new(absolute_path).relative_path_from(@root).to_s
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
platformos-check-0.4.14 lib/platformos_check/in_memory_storage.rb
platformos-check-0.4.13 lib/platformos_check/in_memory_storage.rb
platformos-check-0.4.12 lib/platformos_check/in_memory_storage.rb
platformos-check-0.4.11 lib/platformos_check/in_memory_storage.rb
platformos-check-0.4.10 lib/platformos_check/in_memory_storage.rb
platformos-check-0.4.9 lib/platformos_check/in_memory_storage.rb
platformos-check-0.4.8 lib/platformos_check/in_memory_storage.rb
platformos-check-0.4.7 lib/platformos_check/in_memory_storage.rb
platformos-check-0.4.6 lib/platformos_check/in_memory_storage.rb
platformos-check-0.4.5 lib/platformos_check/in_memory_storage.rb
platformos-check-0.4.4 lib/platformos_check/in_memory_storage.rb