Skip to content

Commit

Permalink
livecheck: Reorder throttle
Browse files Browse the repository at this point in the history
  • Loading branch information
samford committed Mar 21, 2024
1 parent 1c69e90 commit 0f947e0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 31 deletions.
38 changes: 19 additions & 19 deletions Library/Homebrew/livecheck.rb
Expand Up @@ -25,11 +25,11 @@ def initialize(package_or_resource)
@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

Expand Down Expand Up @@ -88,23 +88,6 @@ def regex(pattern = T.unsafe(nil))
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
Expand Down Expand Up @@ -153,6 +136,23 @@ def strategy(symbol = T.unsafe(nil), &block)
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
Expand Down Expand Up @@ -186,10 +186,10 @@ def to_hash
"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
Expand Down
24 changes: 12 additions & 12 deletions Library/Homebrew/test/livecheck_spec.rb
Expand Up @@ -66,17 +66,6 @@
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
Expand Down Expand Up @@ -111,6 +100,17 @@
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" }

Expand Down Expand Up @@ -151,10 +151,10 @@
"cask" => nil,
"formula" => nil,
"regex" => nil,
"throttle" => nil,
"skip" => false,
"skip_msg" => nil,
"strategy" => nil,
"throttle" => nil,
"url" => nil,
},
)
Expand Down

0 comments on commit 0f947e0

Please sign in to comment.