Sha256: c1a7a16e676fe2002da4ecd094a69e1cc4c8bff01346056b550c5b777df15411

Contents?: true

Size: 718 Bytes

Versions: 3

Compression:

Stored size: 718 Bytes

Contents

require 'thread'

module Dassets

  class 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

    class NullStore < 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

  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dassets-0.14.5 lib/dassets/file_store.rb
dassets-0.14.4 lib/dassets/file_store.rb
dassets-0.14.3 lib/dassets/file_store.rb