Include dsl key in cask artifact hash

This commit is contained in:
Rylan Polster 2022-08-25 02:52:40 -04:00
parent 4de680688e
commit 90d22bc7b1
No known key found for this signature in database
GPG Key ID: 46A744940CFF4D64
9 changed files with 64 additions and 28 deletions

View File

@ -1,6 +1,8 @@
# typed: false # typed: false
# frozen_string_literal: true # frozen_string_literal: true
require "active_support/core_ext/object/deep_dup"
module Cask module Cask
module Artifact module Artifact
# Abstract superclass for all artifacts. # Abstract superclass for all artifacts.
@ -127,8 +129,9 @@ module Cask
attr_reader :cask attr_reader :cask
def initialize(cask) def initialize(cask, *dsl_args)
@cask = cask @cask = cask
@dsl_args = dsl_args.deep_dup
end end
def config def config
@ -139,6 +142,10 @@ module Cask
def to_s def to_s
"#{summarize} (#{self.class.english_name})" "#{summarize} (#{self.class.english_name})"
end end
def to_args
@dsl_args.reject(&:blank?)
end
end end
end end
end end

View File

@ -32,6 +32,10 @@ module Cask
abstract_phase(self.class.uninstall_dsl_key) abstract_phase(self.class.uninstall_dsl_key)
end end
def summarize
directives.keys.map(&:to_s).join(", ")
end
private private
def class_for_dsl_key(dsl_key) def class_for_dsl_key(dsl_key)
@ -44,10 +48,6 @@ module Cask
class_for_dsl_key(dsl_key).new(cask).instance_eval(&block) class_for_dsl_key(dsl_key).new(cask).instance_eval(&block)
end end
def summarize
directives.keys.map(&:to_s).join(", ")
end
end end
end end
end end

View File

@ -40,7 +40,7 @@ module Cask
def initialize(cask, directives) def initialize(cask, directives)
directives.assert_valid_keys!(*ORDERED_DIRECTIVES) directives.assert_valid_keys!(*ORDERED_DIRECTIVES)
super(cask) super(cask, **directives)
directives[:signal] = Array(directives[:signal]).flatten.each_slice(2).to_a directives[:signal] = Array(directives[:signal]).flatten.each_slice(2).to_a
@directives = directives @directives = directives

View File

@ -72,7 +72,7 @@ module Cask
attr_reader :path, :args attr_reader :path, :args
def initialize(cask, **args) def initialize(cask, **args)
super(cask) super(cask, **args)
if args.key?(:manual) if args.key?(:manual)
@path = Pathname(args[:manual]) @path = Pathname(args[:manual])

View File

@ -23,7 +23,7 @@ module Cask
end end
def initialize(cask, path, **stanza_options) def initialize(cask, path, **stanza_options)
super(cask) super(cask, path, **stanza_options)
@path = cask.staged_path.join(path) @path = cask.staged_path.join(path)
@stanza_options = stanza_options @stanza_options = stanza_options
end end

View File

@ -42,12 +42,13 @@ module Cask
attr_reader :source, :target attr_reader :source, :target
sig { sig {
params(cask: Cask, source: T.nilable(T.any(String, Pathname)), target: T.nilable(T.any(String, Pathname))) params(cask: Cask, source: T.nilable(T.any(String, Pathname)), target_hash: String)
.void .void
} }
def initialize(cask, source, target: nil) def initialize(cask, source, **target_hash)
super(cask) super(cask, source, **target_hash)
target = target_hash[:target]
@source_string = source.to_s @source_string = source.to_s
@target_string = target.to_s @target_string = target.to_s
source = cask.staged_path.join(source) source = cask.staged_path.join(source)

View File

@ -14,7 +14,7 @@ module Cask
def self.from_args(cask, *args) def self.from_args(cask, *args)
raise CaskInvalidError.new(cask.token, "'stage_only' takes only a single argument: true") if args != [true] raise CaskInvalidError.new(cask.token, "'stage_only' takes only a single argument: true") if args != [true]
new(cask) new(cask, true)
end end
sig { returns(T::Array[T::Boolean]) } sig { returns(T::Array[T::Boolean]) }

View File

@ -235,7 +235,7 @@ module Cask
"installed" => versions.last, "installed" => versions.last,
"outdated" => outdated?, "outdated" => outdated?,
"sha256" => sha256, "sha256" => sha256,
"artifacts" => artifacts.map(&method(:to_h_gsubs)), "artifacts" => artifacts_list,
"caveats" => (to_h_string_gsubs(caveats) unless caveats.empty?), "caveats" => (to_h_string_gsubs(caveats) unless caveats.empty?),
"depends_on" => depends_on, "depends_on" => depends_on,
"conflicts_with" => conflicts_with, "conflicts_with" => conflicts_with,
@ -281,6 +281,19 @@ module Cask
private private
def artifacts_list
artifacts.map do |artifact|
if artifact.is_a? Artifact::AbstractFlightBlock
{ type: artifact.summarize }
else
{
type: artifact.class.dsl_key,
args: to_h_gsubs(artifact.to_args),
}
end
end
end
def to_h_string_gsubs(string) def to_h_string_gsubs(string)
string.to_s string.to_s
.gsub(Dir.home, "$HOME") .gsub(Dir.home, "$HOME")

View File

@ -106,13 +106,19 @@ describe Cask::Cmd::List, :cask do
"outdated": false, "outdated": false,
"sha256": "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94", "sha256": "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94",
"artifacts": [ "artifacts": [
[
"Caffeine.app"
],
{ {
"trash": "$HOME/support/fixtures/cask/caffeine/org.example.caffeine.plist", "type": "app",
"signal": { "args": [
} "Caffeine.app"
]
},
{
"type": "zap",
"args": [
{
"trash": "$HOME/support/fixtures/cask/caffeine/org.example.caffeine.plist"
}
]
} }
], ],
"caveats": null, "caveats": null,
@ -140,9 +146,12 @@ describe Cask::Cmd::List, :cask do
"outdated": false, "outdated": false,
"sha256": "e44ffa103fbf83f55c8d0b1bea309a43b2880798dae8620b1ee8da5e1095ec68", "sha256": "e44ffa103fbf83f55c8d0b1bea309a43b2880798dae8620b1ee8da5e1095ec68",
"artifacts": [ "artifacts": [
[ {
"Transmission.app" "type": "app",
] "args": [
"Transmission.app"
]
}
], ],
"caveats": null, "caveats": null,
"depends_on": { "depends_on": {
@ -172,9 +181,12 @@ describe Cask::Cmd::List, :cask do
"outdated": false, "outdated": false,
"sha256": "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94", "sha256": "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94",
"artifacts": [ "artifacts": [
[ {
"Caffeine.app" "type": "app",
] "args": [
"Caffeine.app"
]
}
], ],
"caveats": null, "caveats": null,
"depends_on": { "depends_on": {
@ -201,9 +213,12 @@ describe Cask::Cmd::List, :cask do
"outdated": false, "outdated": false,
"sha256": "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b", "sha256": "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b",
"artifacts": [ "artifacts": [
[ {
"ThirdParty.app" "type": "app",
] "args": [
"ThirdParty.app"
]
}
], ],
"caveats": null, "caveats": null,
"depends_on": { "depends_on": {