livecheck: Reorder throttle

This commit is contained in:
Sam Ford 2024-03-21 08:19:35 -04:00 committed by Michael Cho
parent 25d07c3838
commit 7681621cd4
No known key found for this signature in database
GPG Key ID: 55E85E28A7CD1E85
2 changed files with 31 additions and 31 deletions

View File

@ -25,11 +25,11 @@ class Livecheck
@referenced_cask_name = nil
@referenced_formula_name = nil
@regex = nil
@throttle = nil
@skip = false
@skip_msg = nil
@strategy = nil
@strategy_block = nil
@throttle = nil
@url = nil
end
@ -88,23 +88,6 @@ class Livecheck
end
end
# Sets the `@throttle` instance variable to the provided `Integer` or returns
# the `@throttle` instance variable when no argument is provided.
sig {
params(
# Throttle rate of version patch number to use for bumpable versions.
rate: T.nilable(Integer),
).returns(T.nilable(Integer))
}
def throttle(rate = T.unsafe(nil))
case rate
when nil
@throttle
when Integer
@throttle = rate
end
end
# Sets the `@skip` instance variable to `true` and sets the `@skip_msg`
# instance variable if a `String` is provided. `@skip` is used to indicate
# that the formula/cask/resource should be skipped and the `skip_msg` very
@ -153,6 +136,23 @@ class Livecheck
sig { returns(T.nilable(Proc)) }
attr_reader :strategy_block
# Sets the `@throttle` instance variable to the provided `Integer` or returns
# the `@throttle` instance variable when no argument is provided.
sig {
params(
# Throttle rate of version patch number to use for bumpable versions.
rate: T.nilable(Integer),
).returns(T.nilable(Integer))
}
def throttle(rate = T.unsafe(nil))
case rate
when nil
@throttle
when Integer
@throttle = rate
end
end
# Sets the `@url` instance variable to the provided argument or returns the
# `@url` instance variable when no argument is provided. The argument can be
# a `String` (a URL) or a supported `Symbol` corresponding to a URL in the
@ -186,10 +186,10 @@ class Livecheck
"cask" => @referenced_cask_name,
"formula" => @referenced_formula_name,
"regex" => @regex,
"throttle" => @throttle,
"skip" => @skip,
"skip_msg" => @skip_msg,
"strategy" => @strategy,
"throttle" => @throttle,
"url" => @url,
}
end

View File

@ -66,17 +66,6 @@ RSpec.describe Livecheck do
end
end
describe "#throttle" do
it "returns nil if not set" do
expect(livecheckable_f.throttle).to be_nil
end
it "returns the Integer if set" do
livecheckable_f.throttle(10)
expect(livecheckable_f.throttle).to eq(10)
end
end
describe "#skip" do
it "sets @skip to true when no argument is provided" do
expect(livecheckable_f.skip).to be true
@ -111,6 +100,17 @@ RSpec.describe Livecheck do
end
end
describe "#throttle" do
it "returns nil if not set" do
expect(livecheckable_f.throttle).to be_nil
end
it "returns the Integer if set" do
livecheckable_f.throttle(10)
expect(livecheckable_f.throttle).to eq(10)
end
end
describe "#url" do
let(:url_string) { "https://brew.sh" }
@ -151,10 +151,10 @@ RSpec.describe Livecheck do
"cask" => nil,
"formula" => nil,
"regex" => nil,
"throttle" => nil,
"skip" => false,
"skip_msg" => nil,
"strategy" => nil,
"throttle" => nil,
"url" => nil,
},
)