Sha256: 9bc4f76cc8f27fcf37cd48ad38c06c814625741e8fef0facee0ccd5d2a1c40b1
Contents?: true
Size: 1.35 KB
Versions: 28
Compression:
Stored size: 1.35 KB
Contents
require 'yaml' require 'zlib' require 'expressir/model' module Expressir module ExpressExp class Cache def self.to_file(file, content, options = {}) root_path = options[:root_path] test_overwrite_version = options[:test_overwrite_version] # don't use, only for tests version = test_overwrite_version || VERSION cache = Model::Cache.new({ version: version, content: content }) hash = cache.to_hash(root_path: root_path, skip_empty: true) yaml = YAML.dump(hash) yaml_compressed = Zlib::Deflate.deflate(yaml) File.binwrite(file, yaml_compressed) end def self.from_file(file, options = {}) root_path = options[:root_path] test_overwrite_version = options[:test_overwrite_version] # don't use, only for tests version = test_overwrite_version || VERSION yaml_compressed = File.binread(file) yaml = Zlib::Inflate.inflate(yaml_compressed) hash = YAML.load(yaml) cache = Model::ModelElement.from_hash(hash, root_path: root_path) if cache.version != version raise CacheLoadError.new("Cache version mismatch, cache version is #{cache.version}, Expressir version is #{version}") end cache.content end end class CacheLoadError < StandardError end end end
Version data entries
28 entries across 28 versions & 1 rubygems