brew/Library/Homebrew/dependable.rb

59 lines
1.0 KiB
Ruby
Raw Normal View History

2020-10-10 14:16:11 +02:00
# typed: true
# frozen_string_literal: true
require "options"
2020-08-14 03:48:04 +02:00
# Shared functions for classes which can be depended upon.
module Dependable
# `:run` and `:linked` are no longer used but keep them here to avoid their
# misuse in future.
RESERVED_TAGS = [:build, :optional, :recommended, :run, :test, :linked, :implicit].freeze
2023-01-22 17:03:27 -08:00
attr_reader :tags
def build?
tags.include? :build
end
def optional?
tags.include? :optional
end
def recommended?
tags.include? :recommended
end
def test?
tags.include? :test
end
def implicit?
tags.include? :implicit
end
2013-05-10 23:45:06 -05:00
def required?
!build? && !test? && !optional? && !recommended?
2013-05-10 23:45:06 -05:00
end
def option_tags
tags - RESERVED_TAGS
end
def options
Options.create(option_tags)
end
def prune_from_option?(build)
return false if !optional? && !recommended?
2018-09-17 02:45:00 +02:00
build.without?(self)
end
def prune_if_build_and_not_dependent?(dependent, formula = nil)
return false unless build?
return dependent.installed? unless formula
2018-09-17 02:45:00 +02:00
dependent != formula
end
end