Class: Sass::CacheStores::Filesystem
- Inherits:
- Base
- Object
- Base
- Sass::CacheStores::Filesystem
- Defined in:
- /Users/ceppstei/Projects/sass-lang/.sass/lib/sass/cache_stores/filesystem.rb
Overview
A backend for the Sass cache using the filesystem.
Instance Attribute Summary (collapse)
- - (String) cache_location
The directory where the cached files will be stored.
Instance Method Summary (collapse)
- - _retrieve(key, version, sha)
- - _store(key, version, sha, contents)
- - (Filesystem) initialize(cache_location) constructor
A new instance of Filesystem.
Methods inherited from Base
Constructor Details
- (Filesystem) initialize(cache_location)
Returns a new instance of Filesystem
13 14 15 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/cache_stores/filesystem.rb', line 13
def initialize(cache_location)
@cache_location = cache_location
end |
Instance Attribute Details
- (String) cache_location
The directory where the cached files will be stored.
10 11 12 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/cache_stores/filesystem.rb', line 10
def cache_location
@cache_location
end |
Instance Method Details
- _retrieve(key, version, sha)
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/cache_stores/filesystem.rb', line 18
def _retrieve(key, version, sha)
return unless File.readable?(path_to(key))
begin
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)
rescue Errno::ENOENT
# Already deleted. Race condition?
end
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)
36 37 38 39 40 41 42 43 44 45 46 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/cache_stores/filesystem.rb', line 36
def _store(key, version, sha, contents)
compiled_filename = path_to(key)
FileUtils.mkdir_p(File.dirname(compiled_filename))
Sass::Util.atomic_create_and_write_file(compiled_filename, 0600) do |f|
f.puts(version)
f.puts(sha)
f.write(contents)
end
rescue Errno::EACCES
# pass
end |