Sha256: 5cb4c0c6d9d68ba0071ba2d63499630d4882f7dc6fea91c4ed31676d14583441

Contents?: true

Size: 819 Bytes

Versions: 2

Compression:

Stored size: 819 Bytes

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 template
# as a big hash already, leave it like that and save yourself some IO.
module ThemeCheck
  class InMemoryStorage < Storage
    def initialize(files = {})
      @files = files
    end

    def path(name)
      name
    end

    def read(name)
      @files[name]
    end

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

    def files
      @values ||= @files.keys
    end

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
theme-check-0.5.0 lib/theme_check/in_memory_storage.rb
theme-check-0.4.0 lib/theme_check/in_memory_storage.rb