Class: Octopress::Gist::Cache
- Inherits:
-
Object
- Object
- Octopress::Gist::Cache
- Defined in:
- lib/octopress-gist/cache.rb
Constant Summary collapse
- GIST_CACHE_DIR =
'.gist-cache'
Class Method Summary collapse
- .get_cache_path(dir, name, str) ⇒ Object
- .read_cache(options) ⇒ Object
- .write_cache(contents, options) ⇒ Object
Class Method Details
.get_cache_path(dir, name, str) ⇒ Object
21 22 23 |
# File 'lib/octopress-gist/cache.rb', line 21 def get_cache_path(dir, name, str) File.join(dir, "#{name}-#{Digest::MD5.hexdigest(str)}.html") end |
.read_cache(options) ⇒ Object
8 9 10 11 |
# File 'lib/octopress-gist/cache.rb', line 8 def read_cache() path = get_cache_path(GIST_CACHE_DIR, [:gist_id], .to_s) File.exist?(path) ? JSON.parse(File.read(path)) : nil end |
.write_cache(contents, options) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/octopress-gist/cache.rb', line 13 def write_cache(contents, ) FileUtils.mkdir_p(GIST_CACHE_DIR) unless File.directory?(GIST_CACHE_DIR) path = get_cache_path(GIST_CACHE_DIR, [:gist_id], .to_s) File.open(path, 'w') do |f| f.print(contents.to_s) end end |