Class: Expressir::Express::Cache
- Inherits:
-
Object
- Object
- Expressir::Express::Cache
- Defined in:
- lib/expressir/express/cache.rb
Class Method Summary collapse
-
.from_file(file, root_path: nil, test_overwrite_version: nil) ⇒ Model::ModelElement
Load Express model from a cache file.
-
.to_file(file, content, root_path: nil, test_overwrite_version: nil) ⇒ nil
Save Express model into a cache file.
Class Method Details
.from_file(file, root_path: nil, test_overwrite_version: nil) ⇒ Model::ModelElement
Load Express model from a cache file
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/expressir/express/cache.rb', line 35 def self.from_file(file, root_path: nil, test_overwrite_version: nil) version = test_overwrite_version || VERSION yaml_compressed = File.binread(file) yaml = Zlib::Inflate.inflate(yaml_compressed) hash = YAML.safe_load(yaml, permitted_classes: [Symbol]) cache = Model::ModelElement.from_hash(hash, root_path: root_path) if cache.version != version raise Error.new("Cache version mismatch, cache version is #{cache.version}, Expressir version is #{version}") end cache.content end |
.to_file(file, content, root_path: nil, test_overwrite_version: nil) ⇒ nil
Save Express model into a cache file
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/expressir/express/cache.rb', line 14 def self.to_file(file, content, root_path: nil, test_overwrite_version: nil) version = test_overwrite_version || VERSION cache = Model::Cache.new( version: version, content: content, ) hash = cache.to_hash(root_path: root_path) yaml = YAML.dump(hash) yaml_compressed = Zlib::Deflate.deflate(yaml) File.binwrite(file, yaml_compressed) nil end |