Module: VivlioStarter::CLI::PreProcessCommands::GeneratedAssetCache
- Defined in:
- lib/vivlio_starter/cli/pre_process/generated_asset_cache.rb
Overview
生成資産の永続キャッシュ(fetch-or-generate + materialize)
Class Method Summary collapse
- .copy_to_workspace(cache, files, out_dir) ⇒ Object
-
.dir(kind) ⇒ Object
種別のキャッシュディレクトリ(.cache/vs/
/)。. -
.fetch(kind, files, out_dir:) {|cache_dir| ... } ⇒ Boolean
キャッシュから生成物一式をワークスペースへ写す。無ければブロックで生成する。.
-
.materialize(kind, files, out_dir:) ⇒ Boolean
キャッシュに揃っている生成物一式をワークスペースへ写す(生成はしない)。 呼び出し元が dir(kind) へ自前バッチ生成した後の配布に使う。.
Class Method Details
.copy_to_workspace(cache, files, out_dir) ⇒ Object
79 80 81 82 83 |
# File 'lib/vivlio_starter/cli/pre_process/generated_asset_cache.rb', line 79 def copy_to_workspace(cache, files, out_dir) FileUtils.mkdir_p(out_dir) files.each { FileUtils.cp(File.join(cache, it), File.join(out_dir, it)) } true end |
.dir(kind) ⇒ Object
種別のキャッシュディレクトリ(.cache/vs/
42 |
# File 'lib/vivlio_starter/cli/pre_process/generated_asset_cache.rb', line 42 def dir(kind) = File.join(Common.cache_dir, kind) |
.fetch(kind, files, out_dir:) {|cache_dir| ... } ⇒ Boolean
キャッシュから生成物一式をワークスペースへ写す。無ければブロックで生成する。
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/vivlio_starter/cli/pre_process/generated_asset_cache.rb', line 52 def fetch(kind, files, out_dir:) return true if files.all? { File.exist?(File.join(out_dir, it)) } cache = dir(kind) unless files.all? { File.exist?(File.join(cache, it)) } FileUtils.mkdir_p(cache) return false unless yield(cache) # 生成側の書き忘れ(成功を返したのにファイルが無い)は縮退として扱う return false unless files.all? { File.exist?(File.join(cache, it)) } end copy_to_workspace(cache, files, out_dir) end |
.materialize(kind, files, out_dir:) ⇒ Boolean
キャッシュに揃っている生成物一式をワークスペースへ写す(生成はしない)。 呼び出し元が dir(kind) へ自前バッチ生成した後の配布に使う。
70 71 72 73 74 75 76 77 |
# File 'lib/vivlio_starter/cli/pre_process/generated_asset_cache.rb', line 70 def materialize(kind, files, out_dir:) return true if files.all? { File.exist?(File.join(out_dir, it)) } cache = dir(kind) return false unless files.all? { File.exist?(File.join(cache, it)) } copy_to_workspace(cache, files, out_dir) end |