Sha256: 2f79b0a473dbd6b52415083a836aef93891ce4b295d5511c01014534d35f254a

Contents?: true

Size: 1.93 KB

Versions: 68

Compression:

Stored size: 1.93 KB

Contents

require 'fileutils'

module Sass
  module CacheStores
    # A backend for the Sass cache using the filesystem.
    class Filesystem < Base
      # The directory where the cached files will be stored.
      #
      # @return [String]
      attr_accessor :cache_location

      # @param cache_location [String] see \{#cache\_location}
      def initialize(cache_location)
        @cache_location = cache_location
      end

      # @see Base#\_retrieve
      def _retrieve(key, version, sha)
        return unless File.readable?(path_to(key))
        File.open(path_to(key), "rb") do |f|
          if f.readline("\n").strip == version && f.readline("\n").strip == sha
            return f.read
          end
        end
        File.unlink path_to(key)
        nil
      rescue EOFError, TypeError, ArgumentError => e
        Sass::Util.sass_warn "Warning. Error encountered while reading cache #{path_to(key)}: #{e}"
      end

      # @see Base#\_store
      def _store(key, version, sha, contents)
        # return unless File.writable?(File.dirname(@cache_location))
        # return if File.exists?(@cache_location) && !File.writable?(@cache_location)
        compiled_filename = path_to(key)
        # return if File.exists?(File.dirname(compiled_filename)) && !File.writable?(File.dirname(compiled_filename))
        # return if File.exists?(compiled_filename) && !File.writable?(compiled_filename)
        FileUtils.mkdir_p(File.dirname(compiled_filename))
        File.open(compiled_filename, "wb") do |f|
          f.puts(version)
          f.puts(sha)
          f.write(contents)
        end
      rescue Errno::EACCES
        #pass
      end

      private

      # Returns the path to a file for the given key.
      #
      # @param key [String]
      # @return [String] The path to the cache file.
      def path_to(key)
        key = key.gsub(/[<>:\\|?*%]/) {|c| "%%%03d" % Sass::Util.ord(c)}
        File.join(cache_location, key)
      end
    end
  end
end

Version data entries

68 entries across 64 versions & 3 rubygems

Version Path
aliddle-sass-3.2.13 lib/sass/cache_stores/filesystem.rb
aliddle-sass-3.2.12 lib/sass/cache_stores/filesystem.rb
aliddle-sass-3.2.11 lib/sass/cache_stores/filesystem.rb
aliddle-sass-1.01 lib/sass/cache_stores/filesystem.rb
aliddle-sass-1.0 lib/sass/cache_stores/filesystem.rb
aliddle-sass-3.2.10 lib/sass/cache_stores/filesystem.rb
sass-3.3.0.alpha.256 lib/sass/cache_stores/filesystem.rb
sass-3.3.0.alpha.255 lib/sass/cache_stores/filesystem.rb
sass-3.3.0.alpha.252 lib/sass/cache_stores/filesystem.rb
sass-3.3.0.alpha.253 lib/sass/cache_stores/filesystem.rb
sass-3.3.0.alpha.247 lib/sass/cache_stores/filesystem.rb
sass-3.3.0.alpha.243 lib/sass/cache_stores/filesystem.rb
sass-3.3.0.alpha.231 lib/sass/cache_stores/filesystem.rb
sass-3.3.0.alpha.229 lib/sass/cache_stores/filesystem.rb
sass-3.3.0.alpha.227 lib/sass/cache_stores/filesystem.rb
sass-3.3.0.alpha.226 lib/sass/cache_stores/filesystem.rb
sass-3.3.0.alpha.225 lib/sass/cache_stores/filesystem.rb
sass-3.3.0.alpha.224 lib/sass/cache_stores/filesystem.rb
sass-3.3.0.alpha.222 lib/sass/cache_stores/filesystem.rb
sass-3.3.0.alpha.218 lib/sass/cache_stores/filesystem.rb