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
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/expressir/express/cache.rb', line 34 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) cache = Model::Cache.from_yaml(yaml) if cache.version != version raise Error::CacheVersionMismatchError.new(cache.version, version) end cache end |
.to_file(file, content, root_path: nil, test_overwrite_version: nil) ⇒ nil
Save Express model into a cache file
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/expressir/express/cache.rb', line 12 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, root_path: root_path, ) yaml = cache.to_yaml yaml_compressed = Zlib::Deflate.deflate(yaml) File.binwrite(file, yaml_compressed) nil end |