class Capsium::Package::Manifest
Attributes
content_path
[R]
String
path
[R]
String
Public Class Methods
(String path) → void
Source
# File lib/capsium/package/manifest.rb, line 16 def initialize(path) @path = path @content_path = File.join(File.dirname(@path), Package::CONTENT_DIR) @config = if File.exist?(path) ManifestConfig.from_json(File.read(path)) else ManifestConfig.new(resources: generate_manifest) end end
Public Instance Methods
(String path) → bool
Source
# File lib/capsium/package/manifest.rb, line 63 def content_file_exists?(path) File.exist?(path_to_content_file(path)) end
() → Hash[String, Resource]
Source
# File lib/capsium/package/manifest.rb, line 29 def generate_manifest content_files.sort.to_h do |file_path| [relative_path(file_path), Resource.new(type: mime_from_path(file_path), visibility: "exported")] end end
Auto-generation (ARCHITECTURE.md section 3): scan content/ recursively, detect MIME types, default visibility โexportedโ, deterministic (sorted) output.
(String path) → Resource?
Source
# File lib/capsium/package/manifest.rb, line 40 def lookup(path) resources[path] end
(String path) → Pathname
Source
# File lib/capsium/package/manifest.rb, line 57 def path_to_content_file(path) raise TypeError, "Path cannot be nil" if path.nil? Pathname.new(File.dirname(@path)).join(path) end
(String path) → String
Source
# File lib/capsium/package/manifest.rb, line 67 def relative_path(path) Pathname.new(path).relative_path_from(File.dirname(@path)).to_s end
() → Hash[String, Resource]
Source
# File lib/capsium/package/manifest.rb, line 36 def resources @config.resources end
(?String output_path) → void
Source
# File lib/capsium/package/manifest.rb, line 53 def save_to_file(output_path = @path) File.write(output_path, to_json) end
(*untyped args) → String
Source
# File lib/capsium/package/manifest.rb, line 49 def to_json(*_args) @config.to_json end
(String path) → String?
Source
# File lib/capsium/package/manifest.rb, line 44 def type_for(path) resource = lookup(path) resource&.type end