Sha256: c24e93da8b1f8e7d032e1c18143f629aa8bdef345ec5442c12598a189b97bd36

Contents?: true

Size: 814 Bytes

Versions: 4

Compression:

Stored size: 814 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

4 entries across 4 versions & 1 rubygems

Version Path
theme-check-0.3.3 lib/theme_check/in_memory_storage.rb
theme-check-0.3.2 lib/theme_check/in_memory_storage.rb
theme-check-0.3.1 lib/theme_check/in_memory_storage.rb
theme-check-0.3.0 lib/theme_check/in_memory_storage.rb