Sha256: 3f8322d3ebe1c47d858c1e3ff049d6b2904dff80bef13479c12904da84555403

Contents?: true

Size: 706 Bytes

Versions: 1

Compression:

Stored size: 706 Bytes

Contents

# frozen_string_literal: true

require "thread"

module Dassets; end

class Dassets::FileStore
  attr_reader :root

  def initialize(root)
    @root       = root
    @save_mutex = ::Mutex.new
  end

  def save(url_path, &block)
    @save_mutex.synchronize do
      store_path(url_path).tap { |path|
        FileUtils.mkdir_p(File.dirname(path))
        File.open(path, "w") { |f| f.write(block.call) }
      }
    end
  end

  def store_path(url_path)
    File.join(@root, url_path)
  end
end

class Dassets::NullFileStore < Dassets::FileStore
  def initialize
    super("")
  end

  def save(url_path, &block)
    # No-op, just return the store path like the base does.
    store_path(url_path)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dassets-0.15.0 lib/dassets/file_store.rb