class Projection
Builds and validates deterministic static projections of installed packages.
Definitions
def initialize(configuration, output: nil)
Initialize a web package projection.
Signature
-
parameter
configurationConfiguration The project configuration.
-
parameter
outputString | Nil An optional project-relative output directory.
Implementation
def initialize(configuration, output: nil)
@configuration = configuration
@output = configuration.output_path(output)
end
attr :configuration
Signature
-
attribute
Configuration The project configuration.
attr :output
Signature
-
attribute
Pathname The static output directory.
def update
Build and atomically replace the static package projection.
Signature
-
returns
Manifest The generated manifest.
-
raises
PackageError If an installed package cannot be materialized safely.
Implementation
def update
FileUtils.mkdir_p(@output.dirname)
Dir.mktmpdir(".web-packages-", @output.dirname.to_s) do |temporary_root|
temporary_root = Pathname.new(temporary_root)
staging = temporary_root + "static"
backup = temporary_root + "backup"
build(staging)
replace(staging, backup)
end
Manifest.load(@output)
end
def check
Check whether the static package projection is current.
Signature
-
returns
Boolean Whether the installed projection matches the desired output.
-
raises
CheckError If the current manifest is missing or malformed.
Implementation
def check
installed = Manifest.load(@output)
Dir.mktmpdir("web-packages-check-") do |temporary_root|
desired = build(Pathname.new(temporary_root) + "static")
return installed.data == desired.data && installed.valid_tree?(@output)
end
end
def check!
Require the static package projection to be current.
Signature
-
returns
Boolean truewhen the projection is current.-
raises
CheckError If the projection is missing or out of date.
Implementation
def check!
unless check
raise CheckError, "The web package projection is out of date. Run `bake web:packages:update`."
end
true
end