Sha256: c59a82696dccb4b7a8fb8f38172c86eeca561bf3a395e204c518fb0193071ec9

Contents?: true

Size: 1.01 KB

Versions: 20

Compression:

Stored size: 1.01 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 template
# as a big hash already, leave it like that and save yourself some IO.
module ThemeCheck
  class InMemoryStorage < Storage
    def initialize(files = {}, root = "/dev/null")
      @files = files
      @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)
      @files[relative_path] = content
    end

    def files
      @files.keys
    end

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

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

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
theme-check-1.5.1 lib/theme_check/in_memory_storage.rb
theme-check-1.5.0 lib/theme_check/in_memory_storage.rb
theme-check-1.4.0 lib/theme_check/in_memory_storage.rb
theme-check-1.3.0 lib/theme_check/in_memory_storage.rb
theme-check-1.2.0 lib/theme_check/in_memory_storage.rb
theme-check-1.1.0 lib/theme_check/in_memory_storage.rb
theme-check-1.0.0 lib/theme_check/in_memory_storage.rb
theme-check-0.10.2 lib/theme_check/in_memory_storage.rb
theme-check-0.10.1 lib/theme_check/in_memory_storage.rb
theme-check-0.10.0 lib/theme_check/in_memory_storage.rb
theme-check-0.9.1 lib/theme_check/in_memory_storage.rb
theme-check-0.9.0 lib/theme_check/in_memory_storage.rb
theme-check-0.8.3 lib/theme_check/in_memory_storage.rb
theme-check-0.8.2 lib/theme_check/in_memory_storage.rb
theme-check-0.8.1 lib/theme_check/in_memory_storage.rb
theme-check-0.8.0 lib/theme_check/in_memory_storage.rb
theme-check-0.7.3 lib/theme_check/in_memory_storage.rb
theme-check-0.7.2 lib/theme_check/in_memory_storage.rb
theme-check-0.7.1 lib/theme_check/in_memory_storage.rb
theme-check-0.7.0 lib/theme_check/in_memory_storage.rb