Class: Sass::FileCacheStore
- Inherits:
-
CacheStore
- Object
- CacheStore
- Sass::FileCacheStore
- Defined in:
- lib/sass/cache_store.rb
Overview
A backend for the Sass cache using the filesystem.
Instance Attribute Summary collapse
-
#cache_location ⇒ String
The directory where the cached files will be stored.
Instance Method Summary collapse
- #_retrieve(key, version, sha)
- #_store(key, version, sha, contents)
-
#initialize(cache_location) ⇒ FileCacheStore
constructor
Create a new FileCacheStore.
Methods inherited from CacheStore
Constructor Details
#initialize(cache_location) ⇒ FileCacheStore
Create a new FileCacheStore.
99 100 101 |
# File 'lib/sass/cache_store.rb', line 99
def initialize(cache_location)
@cache_location = cache_location
end
|
Instance Attribute Details
#cache_location ⇒ String
The directory where the cached files will be stored.
94 95 96 |
# File 'lib/sass/cache_store.rb', line 94
def cache_location
@cache_location
end
|
Instance Method Details
#_retrieve(key, version, sha)
104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/sass/cache_store.rb', line 104
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
Haml::Util.haml_warn "Warning. Error encountered while reading cache #{path_to(key)}: #{e}"
end
|
#_store(key, version, sha, contents)
119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/sass/cache_store.rb', line 119
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
end
|