Skip to content

Commit 97cce36

Browse files
committed
Make os available in cask livecheck blocks
Casks now support an `os` DSL method, similar to `arch`. This makes it available in `livecheck` blocks, like we do with `arch`.
1 parent fc86107 commit 97cce36

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

Library/Homebrew/cask/dsl.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class DSL
8080
:homepage,
8181
:language,
8282
:name,
83+
:os,
8384
:sha256,
8485
:staged_path,
8586
:url,

Library/Homebrew/livecheck.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,10 @@ def url(url = T.unsafe(nil), homebrew_curl: nil, post_form: nil, post_json: nil)
194194
end
195195

196196
delegate url_options: :@options
197-
delegate version: :@package_or_resource
198197
delegate arch: :@package_or_resource
199-
private :version, :arch
198+
delegate os: :@package_or_resource
199+
delegate version: :@package_or_resource
200+
private :arch, :os, :version
200201
# Returns a `Hash` of all instance variable values.
201202
# @return [Hash]
202203
sig { returns(T::Hash[String, T.untyped]) }

Library/Homebrew/test/livecheck_spec.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,32 @@
182182
end
183183
end
184184

185+
describe "#os" do
186+
let(:c_os) do
187+
Cask::Cask.new("c-os") do
188+
os macos: "macos", linux: "linux"
189+
190+
version "0.0.1"
191+
192+
url "https://brew.sh/test-0.0.1.dmg"
193+
name "Test"
194+
desc "Test cask"
195+
homepage "https://brew.sh"
196+
197+
livecheck do
198+
url "https://brew.sh/#{os}"
199+
end
200+
end
201+
end
202+
203+
[:needs_macos, :needs_linux].each do |needs_os|
204+
os_value = needs_os.to_s.delete_prefix("needs_")
205+
it "delegates `os` in `livecheck` block to `package_or_resource`", needs_os do
206+
expect(c_os.livecheck.url).to eq("https://brew.sh/#{os_value}")
207+
end
208+
end
209+
end
210+
185211
describe "#to_hash" do
186212
it "returns a Hash of all instance variables" do
187213
expect(livecheck_f.to_hash).to eq(

0 commit comments

Comments
 (0)