Establish a convention for Requirement names
The name attribute of requirements is used when generating options for the :optional and :recommended dependency tags. Unless otherwise specified, the name attribute of a Requirement will be populated by stripping any module prefixes from the beginning and "Dependency" or "Requirement" from end of the class name and downcasing the result. Closes Homebrew/homebrew#17759.
This commit is contained in:
parent
d71c8beac9
commit
71f85300b4
@ -85,9 +85,9 @@ private
|
||||
Dependency.new(spec.to_s, tag)
|
||||
when :x11 then X11Dependency.new(spec.to_s, tag)
|
||||
when :xcode then XcodeDependency.new(tag)
|
||||
when :mysql then MysqlInstalled.new(tag)
|
||||
when :postgresql then PostgresqlInstalled.new(tag)
|
||||
when :tex then TeXInstalled.new(tag)
|
||||
when :mysql then MysqlDependency.new(tag)
|
||||
when :postgresql then PostgresqlDependency.new(tag)
|
||||
when :tex then TeXDependency.new(tag)
|
||||
when :clt then CLTDependency.new(tag)
|
||||
else
|
||||
raise "Unsupported special dependency #{spec}"
|
||||
|
||||
@ -13,6 +13,7 @@ class Requirement
|
||||
def initialize(*tags)
|
||||
@tags = tags.flatten.compact
|
||||
@tags << :build if self.class.build
|
||||
@name ||= infer_name
|
||||
end
|
||||
|
||||
# The message to show when the requirement is not met.
|
||||
@ -55,6 +56,13 @@ class Requirement
|
||||
|
||||
private
|
||||
|
||||
def infer_name
|
||||
klass = self.class.to_s
|
||||
klass.sub!(/(Dependency|Requirement)$/, '')
|
||||
klass.sub!(/^(\w+::){0,}/, '')
|
||||
klass.downcase
|
||||
end
|
||||
|
||||
def infer_env_modification(o)
|
||||
case o
|
||||
when Pathname
|
||||
|
||||
@ -253,7 +253,7 @@ class XcodeDependency < Requirement
|
||||
end
|
||||
end
|
||||
|
||||
class MysqlInstalled < Requirement
|
||||
class MysqlDependency < Requirement
|
||||
fatal true
|
||||
|
||||
satisfy { which 'mysql_config' }
|
||||
@ -274,7 +274,7 @@ class MysqlInstalled < Requirement
|
||||
end
|
||||
end
|
||||
|
||||
class PostgresqlInstalled < Requirement
|
||||
class PostgresqlDependency < Requirement
|
||||
fatal true
|
||||
|
||||
satisfy { which 'pg_config' }
|
||||
@ -292,7 +292,7 @@ class PostgresqlInstalled < Requirement
|
||||
end
|
||||
end
|
||||
|
||||
class TeXInstalled < Requirement
|
||||
class TeXDependency < Requirement
|
||||
fatal true
|
||||
|
||||
satisfy { which('tex') || which('latex') }
|
||||
|
||||
@ -92,4 +92,12 @@ class RequirementTests < Test::Unit::TestCase
|
||||
req = Class.new(Requirement) { build true }.new
|
||||
assert req.build?
|
||||
end
|
||||
|
||||
def test_infer_name_from_class
|
||||
klass, const = self.class, :FooRequirement
|
||||
klass.const_set(const, Class.new(Requirement))
|
||||
assert_equal "foo", klass.const_get(const).new.name
|
||||
ensure
|
||||
klass.send(:remove_const, const) if klass.const_defined?(const)
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user