Class: Sass::CacheStores::Filesystem

Inherits:
Base
  • Object
show all
Defined in:
lib/sass/cache_stores/filesystem.rb

Overview

A backend for the Sass cache using the filesystem.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#key, #retrieve, #store

Constructor Details

#initialize(cache_location) ⇒ Filesystem

Returns a new instance of Filesystem.

Parameters:



13
14
15
# File 'lib/sass/cache_stores/filesystem.rb', line 13

def initialize(cache_location)
  @cache_location = cache_location
end

Instance Attribute Details

#cache_locationString

The directory where the cached files will be stored.

Returns:

  • (String)


10
11
12
# File 'lib/sass/cache_stores/filesystem.rb', line 10

def cache_location
  @cache_location
end

Instance Method Details

#_retrieve(key, version, sha)

See Also:

  • Base#\_retrieve


18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/sass/cache_stores/filesystem.rb', line 18

def _retrieve(key, version, sha)
  return unless File.readable?(path_to(key))
  contents = nil
  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

#_store(key, version, sha, contents)

See Also:

  • Base#\_store


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/sass/cache_stores/filesystem.rb', line 33

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