Skip to content

Commit

Permalink
Merge pull request Homebrew#16640 from dduugg/finalize-sigs
Browse files Browse the repository at this point in the history
Finalize methods that do not support overrides
  • Loading branch information
MikeMcQuaid authored Feb 20, 2024
2 parents 7abeca1 + e7e4ecc commit aa58637
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
26 changes: 20 additions & 6 deletions Library/Homebrew/requirement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,15 @@ def message
s
end

# Overriding {#satisfied?} is unsupported.
# Pass a block or boolean to the satisfy DSL method instead.
# Pass a block or boolean to the satisfy DSL method instead of overriding.
sig(:final) {
params(
env: T.nilable(String),
cc: T.nilable(String),
build_bottle: T::Boolean,
bottle_arch: T.nilable(String),
).returns(T::Boolean)
}
def satisfied?(env: nil, cc: nil, build_bottle: false, bottle_arch: nil)
satisfy = self.class.satisfy
return true unless satisfy
Expand All @@ -76,8 +83,8 @@ def satisfied?(env: nil, cc: nil, build_bottle: false, bottle_arch: nil)
true
end

# Overriding {#fatal?} is unsupported.
# Pass a boolean to the fatal DSL method instead.
# Pass a boolean to the fatal DSL method instead of overriding.
sig(:final) { returns(T::Boolean) }
def fatal?
self.class.fatal || false
end
Expand All @@ -92,8 +99,15 @@ def satisfied_result_parent
parent
end

# Overriding {#modify_build_environment} is unsupported.
# Pass a block to the env DSL method instead.
# Pass a block to the env DSL method instead of overriding.
sig(:final) {
params(
env: T.nilable(String),
cc: T.nilable(String),
build_bottle: T::Boolean,
bottle_arch: T.nilable(String),
).void
}
def modify_build_environment(env: nil, cc: nil, build_bottle: false, bottle_arch: nil)
satisfied?(env: env, cc: cc, build_bottle: build_bottle, bottle_arch: bottle_arch)
instance_eval(&env_proc) if env_proc
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/test/requirement_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
let(:klass) { Class.new(described_class) }

it "returns nil" do
expect(requirement.modify_build_environment).to be_nil
expect { requirement.modify_build_environment }.not_to raise_error
end
end
end
Expand Down

0 comments on commit aa58637

Please sign in to comment.