Class: Octopress::Gist::Cache

Inherits:
Object
  • Object
show all
Defined in:
lib/octopress-gist/cache.rb

Constant Summary collapse

GIST_CACHE_DIR =
'.gist-cache'

Class Method Summary collapse

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(options)
  path = get_cache_path(GIST_CACHE_DIR, options[:gist_id], options.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, options)
  FileUtils.mkdir_p(GIST_CACHE_DIR) unless File.directory?(GIST_CACHE_DIR)
  path = get_cache_path(GIST_CACHE_DIR, options[:gist_id], options.to_s)
  File.open(path, 'w') do |f|
    f.print(contents.to_s)
  end
end