build_options: typed: strict
Signed-off-by: botantony <antonsm21@gmail.com>
This commit is contained in:
parent
1cc4d0bc25
commit
b2539d37fe
@ -1,11 +1,12 @@
|
|||||||
# typed: true # rubocop:todo Sorbet/StrictSigil
|
# typed: strict
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
# Options for a formula build.
|
# Options for a formula build.
|
||||||
class BuildOptions
|
class BuildOptions
|
||||||
|
sig { params(args: Options, options: Options).void }
|
||||||
def initialize(args, options)
|
def initialize(args, options)
|
||||||
@args = args
|
@args = T.let(args, Options)
|
||||||
@options = options
|
@options = T.let(options, Options)
|
||||||
end
|
end
|
||||||
|
|
||||||
# True if a {Formula} is being built with a specific option.
|
# True if a {Formula} is being built with a specific option.
|
||||||
@ -29,8 +30,13 @@ class BuildOptions
|
|||||||
# args << "--with-example1"
|
# args << "--with-example1"
|
||||||
# end
|
# end
|
||||||
# ```
|
# ```
|
||||||
|
sig { params(val: T.any(String, Requirement, Dependency)).returns(T::Boolean) }
|
||||||
def with?(val)
|
def with?(val)
|
||||||
option_names = val.respond_to?(:option_names) ? val.option_names : [val]
|
option_names = if val.is_a?(String)
|
||||||
|
[val]
|
||||||
|
else
|
||||||
|
val.option_names
|
||||||
|
end
|
||||||
|
|
||||||
option_names.any? do |name|
|
option_names.any? do |name|
|
||||||
if option_defined? "with-#{name}"
|
if option_defined? "with-#{name}"
|
||||||
@ -50,11 +56,13 @@ class BuildOptions
|
|||||||
# ```ruby
|
# ```ruby
|
||||||
# args << "--no-spam-plz" if build.without? "spam"
|
# args << "--no-spam-plz" if build.without? "spam"
|
||||||
# ```
|
# ```
|
||||||
|
sig { params(val: T.any(String, Requirement, Dependency)).returns(T::Boolean) }
|
||||||
def without?(val)
|
def without?(val)
|
||||||
!with?(val)
|
!with?(val)
|
||||||
end
|
end
|
||||||
|
|
||||||
# True if a {Formula} is being built as a bottle (i.e. binary package).
|
# True if a {Formula} is being built as a bottle (i.e. binary package).
|
||||||
|
sig { returns(T::Boolean) }
|
||||||
def bottle?
|
def bottle?
|
||||||
include? "build-bottle"
|
include? "build-bottle"
|
||||||
end
|
end
|
||||||
@ -75,6 +83,7 @@ class BuildOptions
|
|||||||
# args << "--and-a-cold-beer" if build.with? "cold-beer"
|
# args << "--and-a-cold-beer" if build.with? "cold-beer"
|
||||||
# end
|
# end
|
||||||
# ```
|
# ```
|
||||||
|
sig { returns(T::Boolean) }
|
||||||
def head?
|
def head?
|
||||||
include? "HEAD"
|
include? "HEAD"
|
||||||
end
|
end
|
||||||
@ -87,29 +96,35 @@ class BuildOptions
|
|||||||
# ```ruby
|
# ```ruby
|
||||||
# args << "--some-feature" if build.stable?
|
# args << "--some-feature" if build.stable?
|
||||||
# ```
|
# ```
|
||||||
|
sig { returns(T::Boolean) }
|
||||||
def stable?
|
def stable?
|
||||||
!head?
|
!head?
|
||||||
end
|
end
|
||||||
|
|
||||||
# True if the build has any arguments or options specified.
|
# True if the build has any arguments or options specified.
|
||||||
|
sig { returns(T::Boolean) }
|
||||||
def any_args_or_options?
|
def any_args_or_options?
|
||||||
!@args.empty? || !@options.empty?
|
!@args.empty? || !@options.empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { returns(Options) }
|
||||||
def used_options
|
def used_options
|
||||||
@options & @args
|
@options & @args
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { returns(Options) }
|
||||||
def unused_options
|
def unused_options
|
||||||
@options - @args
|
@options - @args
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
sig { params(name: String).returns(T::Boolean) }
|
||||||
def include?(name)
|
def include?(name)
|
||||||
@args.include?("--#{name}")
|
@args.include?("--#{name}")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { params(name: String).returns(T::Boolean) }
|
||||||
def option_defined?(name)
|
def option_defined?(name)
|
||||||
@options.include? name
|
@options.include? name
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user