Sha256: eb969173dbfa4b33c2f7df976bc5d2c4dcbe6493370d878c43aeca1e2e3b68c4

Contents?: true

Size: 757 Bytes

Versions: 11

Compression:

Stored size: 757 Bytes

Contents

module Octopress
  module Gist
    class Cache
      GIST_CACHE_DIR = '.gist-cache'

      class << self

        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

        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

        def get_cache_path(dir, name, str)
          File.join(dir, "#{name}-#{Digest::MD5.hexdigest(str)}.html")
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
octopress-gist-1.3.5 lib/octopress-gist/cache.rb
octopress-gist-1.3.4 lib/octopress-gist/cache.rb
octopress-gist-1.3.3 lib/octopress-gist/cache.rb
octopress-gist-1.3.2 lib/octopress-gist/cache.rb
octopress-gist-1.3.1 lib/octopress-gist/cache.rb
octopress-gist-1.3.0 lib/octopress-gist/cache.rb
octopress-gist-1.2.0 lib/octopress-gist/cache.rb
octopress-gist-1.1.0 lib/octopress-gist/cache.rb
octopress-gist-1.0.2 lib/octopress-gist/cache.rb
octopress-gist-1.0.1 lib/octopress-gist/cache.rb
octopress-gist-1.0.0 lib/octopress-gist/cache.rb