class ConceptQL::Knitter::Cache
Attributes
db[RW]
Public Class Methods
new(db, file, options = {})
click to toggle source
# File lib/conceptql/knitter.rb, line 171 def initialize(db, file, options = {}) @db = db @file = file @options = options.nil? ? {} : options.dup remove_cache if @options[:ignore] end
Public Instance Methods
cache_dir()
click to toggle source
# File lib/conceptql/knitter.rb, line 196 def cache_dir @cache_dir ||= (file.dirname + ".#{hash_it(hash_fodder)}").tap { |d| d.mkpath } end
cache_file_path(str)
click to toggle source
# File lib/conceptql/knitter.rb, line 183 def cache_file_path(str) cache_dir + hash_it(str) end
db_opts()
click to toggle source
# File lib/conceptql/knitter.rb, line 204 def db_opts db.opts.values_at(*%i(adapter user password host database search_path)) end
fetch_or_create(str, &block)
click to toggle source
# File lib/conceptql/knitter.rb, line 187 def fetch_or_create(str, &block) cache_file = cache_file_path(str) return cache_file.read if cache_file.exist? #p ["cache miss for", str, cache_file] output = block.call(cache_file) cache_file.write(output) unless cache_file.exist? cache_file.read end
hash_fodder()
click to toggle source
# File lib/conceptql/knitter.rb, line 200 def hash_fodder (db_opts.inspect + file.basename.to_s) end
hash_it(str)
click to toggle source
# File lib/conceptql/knitter.rb, line 208 def hash_it(str) Digest::SHA256.hexdigest("#{str}") end
remove_cache()
click to toggle source
# File lib/conceptql/knitter.rb, line 178 def remove_cache cache_dir.rmtree @cache_dir = nil end