Sha256: 3f24506ade98cb0930a8407358546ae61f98cf5c2f9908017b6e978c6e81bf7f

Contents?: true

Size: 700 Bytes

Versions: 2

Compression:

Stored size: 700 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 do |path|
        FileUtils.mkdir_p(File.dirname(path))
        File.open(path, "w"){ |f| f.write(block.call) }
      end
    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)
    # No-op, just return the store path like the base does.
    store_path(url_path)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dassets-0.15.2 lib/dassets/file_store.rb
dassets-0.15.1 lib/dassets/file_store.rb