Sha256: 27c08322f2ffeba58bf5eefbf671762da5ecadc1e7cfb3d78bc5d3b9ab60aec9
Contents?: true
Size: 1.35 KB
Versions: 7
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
7 entries across 7 versions & 1 rubygems