Sha256: f14b13370680daedf52948e0de14505c21a7448f7d62577a9ae3c53b2c94f730

Contents?: true

Size: 1.13 KB

Versions: 11

Compression:

Stored size: 1.13 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 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.3 lib/platformos_check/in_memory_storage.rb
platformos-check-0.4.2 lib/platformos_check/in_memory_storage.rb
platformos-check-0.4.1 lib/platformos_check/in_memory_storage.rb
platformos-check-0.4.0 lib/platformos_check/in_memory_storage.rb
platformos-check-0.3.3 lib/platformos_check/in_memory_storage.rb
platformos-check-0.3.1 lib/platformos_check/in_memory_storage.rb
platformos-check-0.3.0 lib/platformos_check/in_memory_storage.rb
platformos-check-0.2.2 lib/platformos_check/in_memory_storage.rb
platformos-check-0.2.1 lib/platformos_check/in_memory_storage.rb
platformos-check-0.2.0 lib/platformos_check/in_memory_storage.rb
platformos-check-0.1.0 lib/platformos_check/in_memory_storage.rb