Module: Textus::Lanes::Ingest::EntryTypes::Asset
- Defined in:
- lib/textus/lanes/ingest/entry_types/asset.rb
Class Method Summary collapse
- .build(path:, lane:, time:, layout:, label: nil) ⇒ Object
- .copy(path, lane:, time:, layout:) ⇒ Object
- .move(old_rel, lane, layout) ⇒ Object
Class Method Details
.build(path:, lane:, time:, layout:, label: nil) ⇒ Object
8 9 10 11 12 |
# File 'lib/textus/lanes/ingest/entry_types/asset.rb', line 8 def build(path:, lane:, time:, layout:, label: nil, **) asset_rel = copy(path, lane:, time:, layout:) { "source" => { "kind" => "asset", "label" => label || File.basename(path) }, "asset" => asset_rel, "ingested_at" => time.utc.iso8601, "body" => nil } end |
.copy(path, lane:, time:, layout:) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/textus/lanes/ingest/entry_types/asset.rb', line 14 def copy(path, lane:, time:, layout:) date_path = time.strftime("%Y/%m/%d") filename = File.basename(path) assets_dir = layout.asset_raw_dir(date_path, lane) FileUtils.mkdir_p(assets_dir) FileUtils.cp(path, File.join(assets_dir, filename)) sentinel = layout.asset_sentinel_path File.write(sentinel, "*\n") unless File.exist?(sentinel) "raw/#{date_path}/#{lane}/#{filename}" end |
.move(old_rel, lane, layout) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/textus/lanes/ingest/entry_types/asset.rb', line 25 def move(old_rel, lane, layout) old_path = layout.asset_resolve(old_rel) return unless File.exist?(old_path) now = Time.now.utc date_path = now.strftime("%Y/%m/%d") filename = File.basename(old_path) new_dir = layout.asset_raw_dir(date_path, lane) new_path = File.join(new_dir, filename) return if old_path == new_path FileUtils.mkdir_p(new_dir) FileUtils.mv(old_path, new_path) rescue Errno::ENOENT, Errno::EACCES => e warn "[textus ingest] could not move asset #{old_rel}: #{e.}" end |