brew/Library/Homebrew/dependable.rb

55 lines
1008 B
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.
#
# @api private
module Dependable
# `:run` and `:linked` are no longer used but keep them here to avoid them being
# misused in future.
RESERVED_TAGS = [:build, :optional, :recommended, :run, :test, :linked].freeze
def build?
tags.include? :build
end
def optional?
tags.include? :optional
end
def recommended?
tags.include? :recommended
end
def test?
tags.include? :test
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 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