class Blur::ScriptCache

Public Class Methods

load(script_name, cache_dir) click to toggle source

Loads the cache file for script_name in cache_dir if it exists.

# File library/blur/script_cache.rb, line 31
def self.load script_name, cache_dir
  cache_path = File.join cache_dir, "#{script_name}.yml"

  if File.exists? cache_path
    object = YAML.load_file cache_path

    ScriptCache.new script_name, cache_path, object
  else
    ScriptCache.new script_name, cache_path, {}
  end
end
new(script_name, path, hash) click to toggle source
# File library/blur/script_cache.rb, line 5
def initialize script_name, path, hash
  @script_name = script_name
  @path = path
  @hash = hash
end

Public Instance Methods

[](key;) click to toggle source

Gets a cache value by its key.

# File library/blur/script_cache.rb, line 12
def [] key; @hash[key] end
[]=(key, value;) click to toggle source

Sets the cache key to the provided value.

# File library/blur/script_cache.rb, line 15
def []= key, value; @hash[key] = value end
save() click to toggle source

Saves the cache as a YAML file.

# File library/blur/script_cache.rb, line 18
def save
  directory = File.dirname @path
  
  unless File.directory? directory
    Dir.mkdir directory
  end

  File.open @path, ?w do |file|
    YAML.dump @hash, file
  end
end