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_cask_name = nil
@referenced_formula_name = nil @referenced_formula_name = nil
@regex = nil @regex = nil
@throttle = nil
@skip = false @skip = false
@skip_msg = nil @skip_msg = nil
@strategy = nil @strategy = nil
@strategy_block = nil @strategy_block = nil
@throttle = nil
@url = nil @url = nil
end end
@ -88,23 +88,6 @@ class Livecheck
end end
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` # Sets the `@skip` instance variable to `true` and sets the `@skip_msg`
# instance variable if a `String` is provided. `@skip` is used to indicate # 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 # that the formula/cask/resource should be skipped and the `skip_msg` very
@ -153,6 +136,23 @@ class Livecheck
sig { returns(T.nilable(Proc)) } sig { returns(T.nilable(Proc)) }
attr_reader :strategy_block 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 # Sets the `@url` instance variable to the provided argument or returns the
# `@url` instance variable when no argument is provided. The argument can be # `@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 # a `String` (a URL) or a supported `Symbol` corresponding to a URL in the
@ -186,10 +186,10 @@ class Livecheck
"cask" => @referenced_cask_name, "cask" => @referenced_cask_name,
"formula" => @referenced_formula_name, "formula" => @referenced_formula_name,
"regex" => @regex, "regex" => @regex,
"throttle" => @throttle,
"skip" => @skip, "skip" => @skip,
"skip_msg" => @skip_msg, "skip_msg" => @skip_msg,
"strategy" => @strategy, "strategy" => @strategy,
"throttle" => @throttle,
"url" => @url, "url" => @url,
} }
end end

View File

@ -66,17 +66,6 @@ RSpec.describe Livecheck do
end end
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 describe "#skip" do
it "sets @skip to true when no argument is provided" do it "sets @skip to true when no argument is provided" do
expect(livecheckable_f.skip).to be true expect(livecheckable_f.skip).to be true
@ -111,6 +100,17 @@ RSpec.describe Livecheck do
end end
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 describe "#url" do
let(:url_string) { "https://brew.sh" } let(:url_string) { "https://brew.sh" }
@ -151,10 +151,10 @@ RSpec.describe Livecheck do
"cask" => nil, "cask" => nil,
"formula" => nil, "formula" => nil,
"regex" => nil, "regex" => nil,
"throttle" => nil,
"skip" => false, "skip" => false,
"skip_msg" => nil, "skip_msg" => nil,
"strategy" => nil, "strategy" => nil,
"throttle" => nil,
"url" => nil, "url" => nil,
}, },
) )